﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibKetoan;

namespace Ketoan
{
	/// <summary>
	/// Summary description for frmKetchuyen.
	/// </summary>
	public class frmKetchuyen : System.Windows.Forms.Form
	{
		#region khai bao bien su dung trong ham
		private DataSet ds=new DataSet();
		private string sql="";		
		private AccessData a;
		private string s_mmyy;
		private string s_mmt="";
		private string s_yy;	
		private string s_yyyy;
		private int l_id;
		private int i_userId;
		private string s_mm;
		private string format_sotien;

		private bool b_khoanmuc1=true,b_khoanmuc2=true,b_khoanmuc3=true,b_khoanmuc4=true;
		private bool b_khoanmucdich1=true,b_khoanmucdich2=true,b_khoanmucdich3=true,b_khoanmucdich4=true;

		private DataTable dtkhoanmuc=new DataTable();
		private DataTable dtkhoanmuc1=new DataTable();
		private DataTable dtkhoanmuc2=new DataTable();
		private DataTable dtkhoanmuc3=new DataTable();
		private DataTable dtkhoanmuc4=new DataTable();
		private DataTable dtkhoanmucdich1=new DataTable();
		private DataTable dtkhoanmucdich2=new DataTable();
		private DataTable dtkhoanmucdich3=new DataTable();
		private DataTable dtkhoanmucdich4=new DataTable();
		private DataTable dtKysl=new DataTable();
		private DataTable dtct=new DataTable();
		
		private Brush disabledTextBrush;
		private Brush currentRowBackBrush;
		private Font currentRowFont;
		private DataTable dtkc=new DataTable();
		private DataTable dt=new DataTable();
		private DataTable dttk=new DataTable();
		private DataTable dtlk=new DataTable();
		private DataTable dtnv=new DataTable();
		private DataGridTableStyle ts;
		private int checkCol=0;
		private bool afterCurrentCellChanged;
		#endregion ket thuc khai bao bien su dung trong ham

		#region khai bao control
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.ComboBox cbono_co;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.CheckBox chkKetchuyen;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.Label label16;
		private System.Windows.Forms.Label label17;
		private System.Windows.Forms.TextBox txtNhomkmcpn;
		private System.Windows.Forms.TextBox txtSobtoan;
		private System.Windows.Forms.TextBox txtTutk;
		private System.Windows.Forms.TextBox txtKmcpnguon;
		private System.Windows.Forms.CheckBox chkKmcpn;
		private System.Windows.Forms.TextBox txtSangtk;
		private System.Windows.Forms.TextBox txtTenbtoan;
		private System.Windows.Forms.TextBox txtKmcpdich;
		private System.Windows.Forms.TextBox txtDtthnguon;
		private System.Windows.Forms.CheckBox chkTuDtthn;
		private System.Windows.Forms.TextBox txtDtthdich;
		private System.Windows.Forms.Button butBoqua;
		private System.Windows.Forms.Button butHuy;
		private System.Windows.Forms.Button butLuu;
		private System.Windows.Forms.Button butSua;
		private System.Windows.Forms.Button butMoi;
		private System.Windows.Forms.Label label18;
		private System.Windows.Forms.Button butKetthuc;
		private System.Windows.Forms.Button butXoa;
		private System.Windows.Forms.CheckBox chkAll;
		
		private System.Windows.Forms.NumericUpDown stt;
		private System.Windows.Forms.ComboBox cboKysl;		
		private LibList.List listkmnguon;
		private LibList.List listkmdich;
		private LibList.List listngvunguon;
		private LibList.List listngvudich;
		private LibList.List listtutk;
		private LibList.List listsangtk;
		private System.Windows.Forms.Button butketchuyen;
		private System.Windows.Forms.Button butcoppy;
		private System.Windows.Forms.Button butlaymau;
		private System.Windows.Forms.Label label19;
		private System.Windows.Forms.Label label20;
		private System.Windows.Forms.Label label21;
		private System.Windows.Forms.Label label22;
		private System.Windows.Forms.Label label23;
		private System.Windows.Forms.Label label24;
		private System.Windows.Forms.Label label25;
		private System.Windows.Forms.Label label26;
		private System.Windows.Forms.Label label27;
		private LibList.List listkmcpdich2;
		private LibList.List listKmcpnguon2;
		private System.Windows.Forms.TextBox txtKmcpdich2;
		private System.Windows.Forms.CheckBox chkkmcpnguon2;
		private System.Windows.Forms.TextBox txtKmcpnguon2;
		private LibList.List listKmcpdich4;
		private LibList.List listKmcpnguon4;
		private System.Windows.Forms.TextBox txtKmcpdich4;
		private System.Windows.Forms.CheckBox chkKmcpnguon4;
		private System.Windows.Forms.TextBox txtKmcpnguon4;
		private LibList.List listKmcpdich3;
		private LibList.List listKmcpnguon3;
		private System.Windows.Forms.TextBox txtKmcpdich3;
		private System.Windows.Forms.CheckBox chkKmcpnguon3;
		private System.Windows.Forms.TextBox txtKmcpnguon3;
		private LibList.List listlkdich;
		private LibList.List listlknguon;
		private System.Windows.Forms.TextBox txtLKdich;
		private System.Windows.Forms.Label label15;
		private System.Windows.Forms.CheckBox chkTulkn;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.TextBox txtLKnguon;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.DataGrid dataGrid2;
		private System.Windows.Forms.Button button1;
		#endregion ket thuc khai bao control
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmKetchuyen(AccessData acc,string mmyy,int i_userid,string yyyy)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			a=acc;
			s_mmyy=mmyy;
			i_userId=i_userid;
			s_mm=mmyy.Substring(0,2).Trim().ToString();
			s_yy=mmyy.Substring(2,2).Trim().ToString();	
			s_yyyy=yyyy;			
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmKetchuyen));
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.txtNhomkmcpn = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.cbono_co = new System.Windows.Forms.ComboBox();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.chkKetchuyen = new System.Windows.Forms.CheckBox();
			this.label7 = new System.Windows.Forms.Label();
			this.txtSobtoan = new System.Windows.Forms.TextBox();
			this.txtTutk = new System.Windows.Forms.TextBox();
			this.txtKmcpnguon = new System.Windows.Forms.TextBox();
			this.label8 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.chkKmcpn = new System.Windows.Forms.CheckBox();
			this.txtSangtk = new System.Windows.Forms.TextBox();
			this.label10 = new System.Windows.Forms.Label();
			this.txtTenbtoan = new System.Windows.Forms.TextBox();
			this.label12 = new System.Windows.Forms.Label();
			this.txtKmcpdich = new System.Windows.Forms.TextBox();
			this.label13 = new System.Windows.Forms.Label();
			this.txtDtthnguon = new System.Windows.Forms.TextBox();
			this.label16 = new System.Windows.Forms.Label();
			this.chkTuDtthn = new System.Windows.Forms.CheckBox();
			this.txtDtthdich = new System.Windows.Forms.TextBox();
			this.label17 = new System.Windows.Forms.Label();
			this.butcoppy = new System.Windows.Forms.Button();
			this.butlaymau = new System.Windows.Forms.Button();
			this.butBoqua = new System.Windows.Forms.Button();
			this.butHuy = new System.Windows.Forms.Button();
			this.butLuu = new System.Windows.Forms.Button();
			this.butSua = new System.Windows.Forms.Button();
			this.butMoi = new System.Windows.Forms.Button();
			this.label18 = new System.Windows.Forms.Label();
			this.butketchuyen = new System.Windows.Forms.Button();
			this.cboKysl = new System.Windows.Forms.ComboBox();
			this.butKetthuc = new System.Windows.Forms.Button();
			this.butXoa = new System.Windows.Forms.Button();
			this.chkAll = new System.Windows.Forms.CheckBox();
			this.stt = new System.Windows.Forms.NumericUpDown();
			this.listtutk = new LibList.List();
			this.listsangtk = new LibList.List();
			this.listkmnguon = new LibList.List();
			this.listkmdich = new LibList.List();
			this.listngvunguon = new LibList.List();
			this.listngvudich = new LibList.List();
			this.listkmcpdich2 = new LibList.List();
			this.listKmcpnguon2 = new LibList.List();
			this.txtKmcpdich2 = new System.Windows.Forms.TextBox();
			this.label19 = new System.Windows.Forms.Label();
			this.chkkmcpnguon2 = new System.Windows.Forms.CheckBox();
			this.label20 = new System.Windows.Forms.Label();
			this.txtKmcpnguon2 = new System.Windows.Forms.TextBox();
			this.label21 = new System.Windows.Forms.Label();
			this.listKmcpdich4 = new LibList.List();
			this.listKmcpnguon4 = new LibList.List();
			this.txtKmcpdich4 = new System.Windows.Forms.TextBox();
			this.label22 = new System.Windows.Forms.Label();
			this.chkKmcpnguon4 = new System.Windows.Forms.CheckBox();
			this.label23 = new System.Windows.Forms.Label();
			this.txtKmcpnguon4 = new System.Windows.Forms.TextBox();
			this.label24 = new System.Windows.Forms.Label();
			this.listKmcpdich3 = new LibList.List();
			this.listKmcpnguon3 = new LibList.List();
			this.txtKmcpdich3 = new System.Windows.Forms.TextBox();
			this.label25 = new System.Windows.Forms.Label();
			this.chkKmcpnguon3 = new System.Windows.Forms.CheckBox();
			this.label26 = new System.Windows.Forms.Label();
			this.txtKmcpnguon3 = new System.Windows.Forms.TextBox();
			this.label27 = new System.Windows.Forms.Label();
			this.listlkdich = new LibList.List();
			this.listlknguon = new LibList.List();
			this.txtLKdich = new System.Windows.Forms.TextBox();
			this.label15 = new System.Windows.Forms.Label();
			this.chkTulkn = new System.Windows.Forms.CheckBox();
			this.label14 = new System.Windows.Forms.Label();
			this.txtLKnguon = new System.Windows.Forms.TextBox();
			this.label11 = new System.Windows.Forms.Label();
			this.dataGrid2 = new System.Windows.Forms.DataGrid();
			this.button1 = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.stt)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).BeginInit();
			this.SuspendLayout();
			// 
			// dataGrid1
			// 
			this.dataGrid1.AlternatingBackColor = System.Drawing.Color.Lavender;
			this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.dataGrid1.BackColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.Control;
			this.dataGrid1.CaptionBackColor = System.Drawing.SystemColors.Control;
			this.dataGrid1.CaptionFont = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.dataGrid1.CaptionForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.DataMember = "";
			this.dataGrid1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.dataGrid1.ForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.GridLineColor = System.Drawing.Color.Gainsboro;
			this.dataGrid1.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
			this.dataGrid1.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
			this.dataGrid1.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid1.LinkColor = System.Drawing.Color.Teal;
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
			this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.PreferredColumnWidth = 20;
			this.dataGrid1.ReadOnly = true;
			this.dataGrid1.RowHeaderWidth = 10;
			this.dataGrid1.SelectionBackColor = System.Drawing.Color.CadetBlue;
			this.dataGrid1.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid1.Size = new System.Drawing.Size(792, 192);
			this.dataGrid1.TabIndex = 91;
			this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(0, 192);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(40, 16);
			this.label1.TabIndex = 92;
			this.label1.Text = "STT: ";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(0, 216);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(40, 16);
			this.label2.TabIndex = 93;
			this.label2.Text = "Nợ/Có:";
			// 
			// txtNhomkmcpn
			// 
			this.txtNhomkmcpn.Location = new System.Drawing.Point(80, 240);
			this.txtNhomkmcpn.Name = "txtNhomkmcpn";
			this.txtNhomkmcpn.Size = new System.Drawing.Size(80, 20);
			this.txtNhomkmcpn.TabIndex = 10;
			this.txtNhomkmcpn.Text = "";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(0, 240);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(74, 24);
			this.label3.TabIndex = 96;
			this.label3.Text = "Nhóm kmcpn:";
			// 
			// cbono_co
			// 
			this.cbono_co.Items.AddRange(new object[] {
														  "Nợ",
														  "Có",
														  "Nợ - Có"});
			this.cbono_co.Location = new System.Drawing.Point(40, 216);
			this.cbono_co.Name = "cbono_co";
			this.cbono_co.Size = new System.Drawing.Size(80, 21);
			this.cbono_co.TabIndex = 4;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(112, 192);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(64, 16);
			this.label4.TabIndex = 1;
			this.label4.Text = "Kết chuyển:";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(120, 216);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(40, 16);
			this.label5.TabIndex = 99;
			this.label5.Text = "Từ TK:";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(160, 240);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(80, 16);
			this.label6.TabIndex = 100;
			this.label6.Text = "Kmcp nguồn 1:";
			// 
			// chkKetchuyen
			// 
			this.chkKetchuyen.Location = new System.Drawing.Point(176, 192);
			this.chkKetchuyen.Name = "chkKetchuyen";
			this.chkKetchuyen.Size = new System.Drawing.Size(16, 16);
			this.chkKetchuyen.TabIndex = 1;
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(200, 192);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(56, 16);
			this.label7.TabIndex = 102;
			this.label7.Text = "Sổ btoán:";
			// 
			// txtSobtoan
			// 
			this.txtSobtoan.Location = new System.Drawing.Point(262, 192);
			this.txtSobtoan.Name = "txtSobtoan";
			this.txtSobtoan.Size = new System.Drawing.Size(128, 20);
			this.txtSobtoan.TabIndex = 2;
			this.txtSobtoan.Text = "";
			// 
			// txtTutk
			// 
			this.txtTutk.Location = new System.Drawing.Point(160, 216);
			this.txtTutk.Name = "txtTutk";
			this.txtTutk.Size = new System.Drawing.Size(80, 20);
			this.txtTutk.TabIndex = 5;
			this.txtTutk.Text = "";
			this.txtTutk.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtTutk_KeyDown);
			this.txtTutk.Validated += new System.EventHandler(this.txtTutk_Validated);
			this.txtTutk.TextChanged += new System.EventHandler(this.txtTutk_TextChanged);
			// 
			// txtKmcpnguon
			// 
			this.txtKmcpnguon.Location = new System.Drawing.Point(238, 240);
			this.txtKmcpnguon.Name = "txtKmcpnguon";
			this.txtKmcpnguon.Size = new System.Drawing.Size(152, 20);
			this.txtKmcpnguon.TabIndex = 11;
			this.txtKmcpnguon.Text = "";
			this.txtKmcpnguon.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtKmcpnguon_KeyDown);
			this.txtKmcpnguon.Validated += new System.EventHandler(this.txtKmcpnguon_Validated);
			this.txtKmcpnguon.TextChanged += new System.EventHandler(this.txtKmcpnguon_TextChanged);
			this.txtKmcpnguon.Enter += new System.EventHandler(this.txtKmcpnguon_Enter);
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(240, 216);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(64, 16);
			this.label8.TabIndex = 106;
			this.label8.Text = "Sang TK:";
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(392, 240);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(72, 16);
			this.label9.TabIndex = 107;
			this.label9.Text = "Từ kmcpn 1:";
			// 
			// chkKmcpn
			// 
			this.chkKmcpn.Location = new System.Drawing.Point(472, 240);
			this.chkKmcpn.Name = "chkKmcpn";
			this.chkKmcpn.Size = new System.Drawing.Size(16, 16);
			this.chkKmcpn.TabIndex = 12;
			this.chkKmcpn.CheckedChanged += new System.EventHandler(this.chkKmcpn_CheckedChanged);
			// 
			// txtSangtk
			// 
			this.txtSangtk.Location = new System.Drawing.Point(294, 216);
			this.txtSangtk.Name = "txtSangtk";
			this.txtSangtk.Size = new System.Drawing.Size(96, 20);
			this.txtSangtk.TabIndex = 6;
			this.txtSangtk.Text = "";
			this.txtSangtk.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtSangtk_KeyDown);
			this.txtSangtk.Validated += new System.EventHandler(this.txtSangtk_Validated);
			this.txtSangtk.TextChanged += new System.EventHandler(this.txtSangtk_TextChanged);
			// 
			// label10
			// 
			this.label10.Location = new System.Drawing.Point(392, 192);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(64, 16);
			this.label10.TabIndex = 110;
			this.label10.Text = "Tên btoán:";
			// 
			// txtTenbtoan
			// 
			this.txtTenbtoan.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txtTenbtoan.Location = new System.Drawing.Point(472, 192);
			this.txtTenbtoan.Name = "txtTenbtoan";
			this.txtTenbtoan.Size = new System.Drawing.Size(312, 20);
			this.txtTenbtoan.TabIndex = 3;
			this.txtTenbtoan.Text = "";
			// 
			// label12
			// 
			this.label12.Location = new System.Drawing.Point(488, 240);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(72, 16);
			this.label12.TabIndex = 113;
			this.label12.Text = "Kmcp đích 1:";
			// 
			// txtKmcpdich
			// 
			this.txtKmcpdich.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txtKmcpdich.Location = new System.Drawing.Point(560, 240);
			this.txtKmcpdich.Name = "txtKmcpdich";
			this.txtKmcpdich.Size = new System.Drawing.Size(224, 20);
			this.txtKmcpdich.TabIndex = 14;
			this.txtKmcpdich.Text = "";
			this.txtKmcpdich.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtKmcpdich_KeyDown);
			this.txtKmcpdich.Validated += new System.EventHandler(this.txtKmcpdich_Validated);
			this.txtKmcpdich.TextChanged += new System.EventHandler(this.txtKmcpdich_TextChanged);
			this.txtKmcpdich.Enter += new System.EventHandler(this.txtKmcpdich_Enter);
			// 
			// label13
			// 
			this.label13.Location = new System.Drawing.Point(392, 288);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(64, 16);
			this.label13.TabIndex = 116;
			this.label13.Text = "Đtth nguồn:";
			// 
			// txtDtthnguon
			// 
			this.txtDtthnguon.Location = new System.Drawing.Point(472, 288);
			this.txtDtthnguon.Name = "txtDtthnguon";
			this.txtDtthnguon.Size = new System.Drawing.Size(72, 20);
			this.txtDtthnguon.TabIndex = 24;
			this.txtDtthnguon.Text = "";
			this.txtDtthnguon.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtDtthnguon_KeyDown);
			this.txtDtthnguon.Validated += new System.EventHandler(this.txtDtthnguon_Validated);
			this.txtDtthnguon.TextChanged += new System.EventHandler(this.txtDtthnguon_TextChanged);
			// 
			// label16
			// 
			this.label16.Location = new System.Drawing.Point(560, 288);
			this.label16.Name = "label16";
			this.label16.Size = new System.Drawing.Size(56, 16);
			this.label16.TabIndex = 122;
			this.label16.Text = "Từ đtthn:";
			// 
			// chkTuDtthn
			// 
			this.chkTuDtthn.Location = new System.Drawing.Point(608, 288);
			this.chkTuDtthn.Name = "chkTuDtthn";
			this.chkTuDtthn.Size = new System.Drawing.Size(16, 16);
			this.chkTuDtthn.TabIndex = 25;
			this.chkTuDtthn.CheckedChanged += new System.EventHandler(this.chkTuDtthn_CheckedChanged);
			// 
			// txtDtthdich
			// 
			this.txtDtthdich.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txtDtthdich.Location = new System.Drawing.Point(688, 288);
			this.txtDtthdich.Name = "txtDtthdich";
			this.txtDtthdich.Size = new System.Drawing.Size(96, 20);
			this.txtDtthdich.TabIndex = 26;
			this.txtDtthdich.Text = "";
			this.txtDtthdich.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtDtthdich_KeyDown);
			this.txtDtthdich.Validated += new System.EventHandler(this.txtDtthdich_Validated);
			this.txtDtthdich.TextChanged += new System.EventHandler(this.txtDtthdich_TextChanged);
			// 
			// label17
			// 
			this.label17.Location = new System.Drawing.Point(640, 288);
			this.label17.Name = "label17";
			this.label17.Size = new System.Drawing.Size(56, 16);
			this.label17.TabIndex = 124;
			this.label17.Text = "Đtth đích:";
			// 
			// butcoppy
			// 
			this.butcoppy.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
			this.butcoppy.Image = ((System.Drawing.Bitmap)(resources.GetObject("butcoppy.Image")));
			this.butcoppy.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butcoppy.Location = new System.Drawing.Point(384, 312);
			this.butcoppy.Name = "butcoppy";
			this.butcoppy.Size = new System.Drawing.Size(80, 25);
			this.butcoppy.TabIndex = 29;
			this.butcoppy.Text = "&Sao chép";
			this.butcoppy.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butcoppy.Click += new System.EventHandler(this.butcoppy_Click);
			// 
			// butlaymau
			// 
			this.butlaymau.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
			this.butlaymau.Image = ((System.Drawing.Bitmap)(resources.GetObject("butlaymau.Image")));
			this.butlaymau.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butlaymau.Location = new System.Drawing.Point(296, 312);
			this.butlaymau.Name = "butlaymau";
			this.butlaymau.Size = new System.Drawing.Size(88, 25);
			this.butlaymau.TabIndex = 28;
			this.butlaymau.Text = " &Lấy từ mẫu";
			this.butlaymau.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butlaymau.Click += new System.EventHandler(this.butlaymau_Click);
			// 
			// butBoqua
			// 
			this.butBoqua.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
			this.butBoqua.Enabled = false;
			this.butBoqua.Image = ((System.Drawing.Bitmap)(resources.GetObject("butBoqua.Image")));
			this.butBoqua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butBoqua.Location = new System.Drawing.Point(704, 312);
			this.butBoqua.Name = "butBoqua";
			this.butBoqua.Size = new System.Drawing.Size(60, 25);
			this.butBoqua.TabIndex = 34;
			this.butBoqua.Text = "&Bỏ qua";
			this.butBoqua.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butBoqua.Click += new System.EventHandler(this.butBoqua_Click);
			// 
			// butHuy
			// 
			this.butHuy.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
			this.butHuy.Image = ((System.Drawing.Bitmap)(resources.GetObject("butHuy.Image")));
			this.butHuy.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butHuy.Location = new System.Drawing.Point(644, 312);
			this.butHuy.Name = "butHuy";
			this.butHuy.Size = new System.Drawing.Size(60, 25);
			this.butHuy.TabIndex = 33;
			this.butHuy.Text = "     &Hủy";
			this.butHuy.Click += new System.EventHandler(this.butHuy_Click);
			// 
			// butLuu
			// 
			this.butLuu.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
			this.butLuu.Enabled = false;
			this.butLuu.Image = ((System.Drawing.Bitmap)(resources.GetObject("butLuu.Image")));
			this.butLuu.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butLuu.Location = new System.Drawing.Point(584, 312);
			this.butLuu.Name = "butLuu";
			this.butLuu.Size = new System.Drawing.Size(60, 25);
			this.butLuu.TabIndex = 32;
			this.butLuu.Text = "     &Lưu";
			this.butLuu.Click += new System.EventHandler(this.butLuu_Click);
			// 
			// butSua
			// 
			this.butSua.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
			this.butSua.Image = ((System.Drawing.Bitmap)(resources.GetObject("butSua.Image")));
			this.butSua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butSua.Location = new System.Drawing.Point(524, 312);
			this.butSua.Name = "butSua";
			this.butSua.Size = new System.Drawing.Size(60, 25);
			this.butSua.TabIndex = 31;
			this.butSua.Text = "     &Sửa";
			this.butSua.Click += new System.EventHandler(this.butSua_Click);
			// 
			// butMoi
			// 
			this.butMoi.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
			this.butMoi.Image = ((System.Drawing.Bitmap)(resources.GetObject("butMoi.Image")));
			this.butMoi.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butMoi.Location = new System.Drawing.Point(464, 312);
			this.butMoi.Name = "butMoi";
			this.butMoi.Size = new System.Drawing.Size(60, 25);
			this.butMoi.TabIndex = 30;
			this.butMoi.Text = "      &Mới";
			this.butMoi.Click += new System.EventHandler(this.butMoi_Click);
			// 
			// label18
			// 
			this.label18.Location = new System.Drawing.Point(0, 312);
			this.label18.Name = "label18";
			this.label18.Size = new System.Drawing.Size(64, 16);
			this.label18.TabIndex = 141;
			this.label18.Text = "Kỳ số liệu:";
			// 
			// butketchuyen
			// 
			this.butketchuyen.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			this.butketchuyen.Image = ((System.Drawing.Bitmap)(resources.GetObject("butketchuyen.Image")));
			this.butketchuyen.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butketchuyen.Location = new System.Drawing.Point(264, 544);
			this.butketchuyen.Name = "butketchuyen";
			this.butketchuyen.Size = new System.Drawing.Size(88, 25);
			this.butketchuyen.TabIndex = 35;
			this.butketchuyen.Text = "&Kết chuyển";
			this.butketchuyen.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butketchuyen.Click += new System.EventHandler(this.butketchuyen_Click);
			// 
			// cboKysl
			// 
			this.cboKysl.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboKysl.Location = new System.Drawing.Point(80, 312);
			this.cboKysl.Name = "cboKysl";
			this.cboKysl.Size = new System.Drawing.Size(208, 21);
			this.cboKysl.TabIndex = 27;
			this.cboKysl.SelectedIndexChanged += new System.EventHandler(this.cboKysl_SelectedIndexChanged);
			// 
			// butKetthuc
			// 
			this.butKetthuc.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			this.butKetthuc.Image = ((System.Drawing.Bitmap)(resources.GetObject("butKetthuc.Image")));
			this.butKetthuc.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butKetthuc.Location = new System.Drawing.Point(472, 544);
			this.butKetthuc.Name = "butKetthuc";
			this.butKetthuc.Size = new System.Drawing.Size(70, 25);
			this.butKetthuc.TabIndex = 38;
			this.butKetthuc.Text = "&Kết thúc";
			this.butKetthuc.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butKetthuc.Click += new System.EventHandler(this.butKetthuc_Click);
			// 
			// butXoa
			// 
			this.butXoa.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			this.butXoa.Enabled = false;
			this.butXoa.Image = ((System.Drawing.Bitmap)(resources.GetObject("butXoa.Image")));
			this.butXoa.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butXoa.Location = new System.Drawing.Point(412, 544);
			this.butXoa.Name = "butXoa";
			this.butXoa.Size = new System.Drawing.Size(60, 25);
			this.butXoa.TabIndex = 37;
			this.butXoa.Text = "     &Xóa";
			this.butXoa.Click += new System.EventHandler(this.butXoa_Click);
			// 
			// chkAll
			// 
			this.chkAll.Appearance = System.Windows.Forms.Appearance.Button;
			this.chkAll.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.chkAll.Location = new System.Drawing.Point(64, -2);
			this.chkAll.Name = "chkAll";
			this.chkAll.Size = new System.Drawing.Size(23, 21);
			this.chkAll.TabIndex = 149;
			this.chkAll.Text = "...";
			this.chkAll.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			this.chkAll.CheckedChanged += new System.EventHandler(this.chkAll_CheckedChanged);
			// 
			// stt
			// 
			this.stt.Enabled = false;
			this.stt.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.stt.Location = new System.Drawing.Point(40, 192);
			this.stt.Name = "stt";
			this.stt.Size = new System.Drawing.Size(61, 21);
			this.stt.TabIndex = 0;
			// 
			// listtutk
			// 
			this.listtutk.BackColor = System.Drawing.SystemColors.Info;
			this.listtutk.ColumnCount = 0;
			this.listtutk.Location = new System.Drawing.Point(176, 216);
			this.listtutk.MatchBufferTimeOut = 1000;
			this.listtutk.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listtutk.Name = "listtutk";
			this.listtutk.Size = new System.Drawing.Size(32, 17);
			this.listtutk.TabIndex = 151;
			this.listtutk.TextIndex = -1;
			this.listtutk.TextMember = null;
			this.listtutk.ValueIndex = -1;
			this.listtutk.Visible = false;
			// 
			// listsangtk
			// 
			this.listsangtk.BackColor = System.Drawing.SystemColors.Info;
			this.listsangtk.ColumnCount = 0;
			this.listsangtk.Location = new System.Drawing.Point(344, 216);
			this.listsangtk.MatchBufferTimeOut = 1000;
			this.listsangtk.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listsangtk.Name = "listsangtk";
			this.listsangtk.Size = new System.Drawing.Size(32, 17);
			this.listsangtk.TabIndex = 152;
			this.listsangtk.TextIndex = -1;
			this.listsangtk.TextMember = null;
			this.listsangtk.ValueIndex = -1;
			this.listsangtk.Visible = false;
			// 
			// listkmnguon
			// 
			this.listkmnguon.BackColor = System.Drawing.SystemColors.Info;
			this.listkmnguon.ColumnCount = 0;
			this.listkmnguon.Location = new System.Drawing.Point(296, 240);
			this.listkmnguon.MatchBufferTimeOut = 1000;
			this.listkmnguon.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listkmnguon.Name = "listkmnguon";
			this.listkmnguon.Size = new System.Drawing.Size(32, 17);
			this.listkmnguon.TabIndex = 155;
			this.listkmnguon.TextIndex = -1;
			this.listkmnguon.TextMember = null;
			this.listkmnguon.ValueIndex = -1;
			this.listkmnguon.Visible = false;
			// 
			// listkmdich
			// 
			this.listkmdich.BackColor = System.Drawing.SystemColors.Info;
			this.listkmdich.ColumnCount = 0;
			this.listkmdich.Location = new System.Drawing.Point(640, 240);
			this.listkmdich.MatchBufferTimeOut = 1000;
			this.listkmdich.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listkmdich.Name = "listkmdich";
			this.listkmdich.Size = new System.Drawing.Size(32, 17);
			this.listkmdich.TabIndex = 156;
			this.listkmdich.TextIndex = -1;
			this.listkmdich.TextMember = null;
			this.listkmdich.ValueIndex = -1;
			this.listkmdich.Visible = false;
			// 
			// listngvunguon
			// 
			this.listngvunguon.BackColor = System.Drawing.SystemColors.Info;
			this.listngvunguon.ColumnCount = 0;
			this.listngvunguon.Location = new System.Drawing.Point(488, 288);
			this.listngvunguon.MatchBufferTimeOut = 1000;
			this.listngvunguon.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listngvunguon.Name = "listngvunguon";
			this.listngvunguon.Size = new System.Drawing.Size(32, 17);
			this.listngvunguon.TabIndex = 157;
			this.listngvunguon.TextIndex = -1;
			this.listngvunguon.TextMember = null;
			this.listngvunguon.ValueIndex = -1;
			this.listngvunguon.Visible = false;
			// 
			// listngvudich
			// 
			this.listngvudich.BackColor = System.Drawing.SystemColors.Info;
			this.listngvudich.ColumnCount = 0;
			this.listngvudich.Location = new System.Drawing.Point(712, 288);
			this.listngvudich.MatchBufferTimeOut = 1000;
			this.listngvudich.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listngvudich.Name = "listngvudich";
			this.listngvudich.Size = new System.Drawing.Size(32, 17);
			this.listngvudich.TabIndex = 158;
			this.listngvudich.TextIndex = -1;
			this.listngvudich.TextMember = null;
			this.listngvudich.ValueIndex = -1;
			this.listngvudich.Visible = false;
			// 
			// listkmcpdich2
			// 
			this.listkmcpdich2.BackColor = System.Drawing.SystemColors.Info;
			this.listkmcpdich2.ColumnCount = 0;
			this.listkmcpdich2.Location = new System.Drawing.Point(328, 264);
			this.listkmcpdich2.MatchBufferTimeOut = 1000;
			this.listkmcpdich2.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listkmcpdich2.Name = "listkmcpdich2";
			this.listkmcpdich2.Size = new System.Drawing.Size(32, 17);
			this.listkmcpdich2.TabIndex = 166;
			this.listkmcpdich2.TextIndex = -1;
			this.listkmcpdich2.TextMember = null;
			this.listkmcpdich2.ValueIndex = -1;
			this.listkmcpdich2.Visible = false;
			// 
			// listKmcpnguon2
			// 
			this.listKmcpnguon2.BackColor = System.Drawing.SystemColors.Info;
			this.listKmcpnguon2.ColumnCount = 0;
			this.listKmcpnguon2.Location = new System.Drawing.Point(88, 264);
			this.listKmcpnguon2.MatchBufferTimeOut = 1000;
			this.listKmcpnguon2.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listKmcpnguon2.Name = "listKmcpnguon2";
			this.listKmcpnguon2.Size = new System.Drawing.Size(32, 17);
			this.listKmcpnguon2.TabIndex = 165;
			this.listKmcpnguon2.TextIndex = -1;
			this.listKmcpnguon2.TextMember = null;
			this.listKmcpnguon2.ValueIndex = -1;
			this.listKmcpnguon2.Visible = false;
			// 
			// txtKmcpdich2
			// 
			this.txtKmcpdich2.Location = new System.Drawing.Point(310, 264);
			this.txtKmcpdich2.Name = "txtKmcpdich2";
			this.txtKmcpdich2.Size = new System.Drawing.Size(80, 20);
			this.txtKmcpdich2.TabIndex = 17;
			this.txtKmcpdich2.Text = "";
			this.txtKmcpdich2.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtKmcpdich2_KeyDown);
			this.txtKmcpdich2.Validated += new System.EventHandler(this.txtKmcpdich2_Validated);
			this.txtKmcpdich2.TextChanged += new System.EventHandler(this.txtKmcpdich2_TextChanged);
			this.txtKmcpdich2.Enter += new System.EventHandler(this.txtKmcpdich2_Enter);
			// 
			// label19
			// 
			this.label19.Location = new System.Drawing.Point(240, 264);
			this.label19.Name = "label19";
			this.label19.Size = new System.Drawing.Size(72, 16);
			this.label19.TabIndex = 164;
			this.label19.Text = "Kmcp đích 2:";
			// 
			// chkkmcpnguon2
			// 
			this.chkkmcpnguon2.Location = new System.Drawing.Point(224, 264);
			this.chkkmcpnguon2.Name = "chkkmcpnguon2";
			this.chkkmcpnguon2.Size = new System.Drawing.Size(16, 16);
			this.chkkmcpnguon2.TabIndex = 16;
			this.chkkmcpnguon2.CheckedChanged += new System.EventHandler(this.chkkmcpnguon2_CheckedChanged);
			// 
			// label20
			// 
			this.label20.Location = new System.Drawing.Point(160, 264);
			this.label20.Name = "label20";
			this.label20.Size = new System.Drawing.Size(72, 16);
			this.label20.TabIndex = 163;
			this.label20.Text = "Từ kmcpn 2:";
			// 
			// txtKmcpnguon2
			// 
			this.txtKmcpnguon2.Location = new System.Drawing.Point(80, 264);
			this.txtKmcpnguon2.Name = "txtKmcpnguon2";
			this.txtKmcpnguon2.Size = new System.Drawing.Size(80, 20);
			this.txtKmcpnguon2.TabIndex = 15;
			this.txtKmcpnguon2.Text = "";
			this.txtKmcpnguon2.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtKmcpnguon2_KeyDown);
			this.txtKmcpnguon2.Validated += new System.EventHandler(this.txtKmcpnguon2_Validated);
			this.txtKmcpnguon2.TextChanged += new System.EventHandler(this.txtKmcpnguon2_TextChanged);
			this.txtKmcpnguon2.Enter += new System.EventHandler(this.txtKmcpnguon2_Enter);
			// 
			// label21
			// 
			this.label21.Location = new System.Drawing.Point(0, 264);
			this.label21.Name = "label21";
			this.label21.Size = new System.Drawing.Size(80, 16);
			this.label21.TabIndex = 162;
			this.label21.Text = "Kmcp nguồn 2:";
			// 
			// listKmcpdich4
			// 
			this.listKmcpdich4.BackColor = System.Drawing.SystemColors.Info;
			this.listKmcpdich4.ColumnCount = 0;
			this.listKmcpdich4.Location = new System.Drawing.Point(328, 288);
			this.listKmcpdich4.MatchBufferTimeOut = 1000;
			this.listKmcpdich4.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listKmcpdich4.Name = "listKmcpdich4";
			this.listKmcpdich4.Size = new System.Drawing.Size(32, 17);
			this.listKmcpdich4.TabIndex = 182;
			this.listKmcpdich4.TextIndex = -1;
			this.listKmcpdich4.TextMember = null;
			this.listKmcpdich4.ValueIndex = -1;
			this.listKmcpdich4.Visible = false;
			// 
			// listKmcpnguon4
			// 
			this.listKmcpnguon4.BackColor = System.Drawing.SystemColors.Info;
			this.listKmcpnguon4.ColumnCount = 0;
			this.listKmcpnguon4.Location = new System.Drawing.Point(96, 288);
			this.listKmcpnguon4.MatchBufferTimeOut = 1000;
			this.listKmcpnguon4.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listKmcpnguon4.Name = "listKmcpnguon4";
			this.listKmcpnguon4.Size = new System.Drawing.Size(32, 17);
			this.listKmcpnguon4.TabIndex = 181;
			this.listKmcpnguon4.TextIndex = -1;
			this.listKmcpnguon4.TextMember = null;
			this.listKmcpnguon4.ValueIndex = -1;
			this.listKmcpnguon4.Visible = false;
			// 
			// txtKmcpdich4
			// 
			this.txtKmcpdich4.Location = new System.Drawing.Point(310, 288);
			this.txtKmcpdich4.Name = "txtKmcpdich4";
			this.txtKmcpdich4.Size = new System.Drawing.Size(80, 20);
			this.txtKmcpdich4.TabIndex = 23;
			this.txtKmcpdich4.Text = "";
			this.txtKmcpdich4.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtKmcpdich4_KeyDown);
			this.txtKmcpdich4.Validated += new System.EventHandler(this.txtKmcpdich4_Validated);
			this.txtKmcpdich4.TextChanged += new System.EventHandler(this.txtKmcpdich4_TextChanged);
			this.txtKmcpdich4.Enter += new System.EventHandler(this.txtKmcpdich4_Enter);
			// 
			// label22
			// 
			this.label22.Location = new System.Drawing.Point(240, 288);
			this.label22.Name = "label22";
			this.label22.Size = new System.Drawing.Size(72, 16);
			this.label22.TabIndex = 180;
			this.label22.Text = "Kmcp đích 4:";
			// 
			// chkKmcpnguon4
			// 
			this.chkKmcpnguon4.Location = new System.Drawing.Point(224, 288);
			this.chkKmcpnguon4.Name = "chkKmcpnguon4";
			this.chkKmcpnguon4.Size = new System.Drawing.Size(16, 16);
			this.chkKmcpnguon4.TabIndex = 22;
			this.chkKmcpnguon4.CheckedChanged += new System.EventHandler(this.chkKmcpnguon4_CheckedChanged);
			// 
			// label23
			// 
			this.label23.Location = new System.Drawing.Point(160, 288);
			this.label23.Name = "label23";
			this.label23.Size = new System.Drawing.Size(72, 16);
			this.label23.TabIndex = 179;
			this.label23.Text = "Từ kmcpn 4:";
			// 
			// txtKmcpnguon4
			// 
			this.txtKmcpnguon4.Location = new System.Drawing.Point(80, 288);
			this.txtKmcpnguon4.Name = "txtKmcpnguon4";
			this.txtKmcpnguon4.Size = new System.Drawing.Size(80, 20);
			this.txtKmcpnguon4.TabIndex = 21;
			this.txtKmcpnguon4.Text = "";
			this.txtKmcpnguon4.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtKmcpnguon4_KeyDown);
			this.txtKmcpnguon4.Validated += new System.EventHandler(this.txtKmcpnguon4_Validated);
			this.txtKmcpnguon4.TextChanged += new System.EventHandler(this.txtKmcpnguon4_TextChanged);
			this.txtKmcpnguon4.Enter += new System.EventHandler(this.txtKmcpnguon4_Enter);
			// 
			// label24
			// 
			this.label24.Location = new System.Drawing.Point(0, 288);
			this.label24.Name = "label24";
			this.label24.Size = new System.Drawing.Size(80, 16);
			this.label24.TabIndex = 178;
			this.label24.Text = "Kmcp nguồn 4:";
			// 
			// listKmcpdich3
			// 
			this.listKmcpdich3.BackColor = System.Drawing.SystemColors.Info;
			this.listKmcpdich3.ColumnCount = 0;
			this.listKmcpdich3.Location = new System.Drawing.Point(712, 264);
			this.listKmcpdich3.MatchBufferTimeOut = 1000;
			this.listKmcpdich3.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listKmcpdich3.Name = "listKmcpdich3";
			this.listKmcpdich3.Size = new System.Drawing.Size(32, 17);
			this.listKmcpdich3.TabIndex = 174;
			this.listKmcpdich3.TextIndex = -1;
			this.listKmcpdich3.TextMember = null;
			this.listKmcpdich3.ValueIndex = -1;
			this.listKmcpdich3.Visible = false;
			// 
			// listKmcpnguon3
			// 
			this.listKmcpnguon3.BackColor = System.Drawing.SystemColors.Info;
			this.listKmcpnguon3.ColumnCount = 0;
			this.listKmcpnguon3.Location = new System.Drawing.Point(504, 264);
			this.listKmcpnguon3.MatchBufferTimeOut = 1000;
			this.listKmcpnguon3.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listKmcpnguon3.Name = "listKmcpnguon3";
			this.listKmcpnguon3.Size = new System.Drawing.Size(32, 17);
			this.listKmcpnguon3.TabIndex = 173;
			this.listKmcpnguon3.TextIndex = -1;
			this.listKmcpnguon3.TextMember = null;
			this.listKmcpnguon3.ValueIndex = -1;
			this.listKmcpnguon3.Visible = false;
			// 
			// txtKmcpdich3
			// 
			this.txtKmcpdich3.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txtKmcpdich3.Location = new System.Drawing.Point(688, 264);
			this.txtKmcpdich3.Name = "txtKmcpdich3";
			this.txtKmcpdich3.Size = new System.Drawing.Size(96, 20);
			this.txtKmcpdich3.TabIndex = 20;
			this.txtKmcpdich3.Text = "";
			this.txtKmcpdich3.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtKmcpdich3_KeyDown);
			this.txtKmcpdich3.Validated += new System.EventHandler(this.txtKmcpdich3_Validated);
			this.txtKmcpdich3.TextChanged += new System.EventHandler(this.txtKmcpdich3_TextChanged);
			this.txtKmcpdich3.Enter += new System.EventHandler(this.txtKmcpdich3_Enter);
			// 
			// label25
			// 
			this.label25.Location = new System.Drawing.Point(624, 264);
			this.label25.Name = "label25";
			this.label25.Size = new System.Drawing.Size(72, 16);
			this.label25.TabIndex = 172;
			this.label25.Text = "Kmcp đích 3:";
			// 
			// chkKmcpnguon3
			// 
			this.chkKmcpnguon3.Location = new System.Drawing.Point(608, 264);
			this.chkKmcpnguon3.Name = "chkKmcpnguon3";
			this.chkKmcpnguon3.Size = new System.Drawing.Size(16, 16);
			this.chkKmcpnguon3.TabIndex = 19;
			this.chkKmcpnguon3.CheckedChanged += new System.EventHandler(this.chkKmcpnguon3_CheckedChanged);
			// 
			// label26
			// 
			this.label26.Location = new System.Drawing.Point(544, 264);
			this.label26.Name = "label26";
			this.label26.Size = new System.Drawing.Size(72, 16);
			this.label26.TabIndex = 171;
			this.label26.Text = "Từ kmcpn 3:";
			// 
			// txtKmcpnguon3
			// 
			this.txtKmcpnguon3.Location = new System.Drawing.Point(472, 264);
			this.txtKmcpnguon3.Name = "txtKmcpnguon3";
			this.txtKmcpnguon3.Size = new System.Drawing.Size(72, 20);
			this.txtKmcpnguon3.TabIndex = 18;
			this.txtKmcpnguon3.Text = "";
			this.txtKmcpnguon3.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtKmpnguon3_KeyDown);
			this.txtKmcpnguon3.Validated += new System.EventHandler(this.txtKmcpnguon3_Validated);
			this.txtKmcpnguon3.TextChanged += new System.EventHandler(this.txtKmcpnguon3_TextChanged);
			this.txtKmcpnguon3.Enter += new System.EventHandler(this.txtKmcpnguon3_Enter);
			// 
			// label27
			// 
			this.label27.Location = new System.Drawing.Point(392, 264);
			this.label27.Name = "label27";
			this.label27.Size = new System.Drawing.Size(80, 16);
			this.label27.TabIndex = 170;
			this.label27.Text = "Kmcp nguồn 3:";
			// 
			// listlkdich
			// 
			this.listlkdich.BackColor = System.Drawing.SystemColors.Info;
			this.listlkdich.ColumnCount = 0;
			this.listlkdich.Location = new System.Drawing.Point(712, 216);
			this.listlkdich.MatchBufferTimeOut = 1000;
			this.listlkdich.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listlkdich.Name = "listlkdich";
			this.listlkdich.Size = new System.Drawing.Size(32, 17);
			this.listlkdich.TabIndex = 190;
			this.listlkdich.TextIndex = -1;
			this.listlkdich.TextMember = null;
			this.listlkdich.ValueIndex = -1;
			this.listlkdich.Visible = false;
			// 
			// listlknguon
			// 
			this.listlknguon.BackColor = System.Drawing.SystemColors.Info;
			this.listlknguon.ColumnCount = 0;
			this.listlknguon.Location = new System.Drawing.Point(496, 216);
			this.listlknguon.MatchBufferTimeOut = 1000;
			this.listlknguon.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listlknguon.Name = "listlknguon";
			this.listlknguon.Size = new System.Drawing.Size(40, 17);
			this.listlknguon.TabIndex = 189;
			this.listlknguon.TextIndex = -1;
			this.listlknguon.TextMember = null;
			this.listlknguon.ValueIndex = -1;
			this.listlknguon.Visible = false;
			// 
			// txtLKdich
			// 
			this.txtLKdich.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txtLKdich.Location = new System.Drawing.Point(688, 216);
			this.txtLKdich.Name = "txtLKdich";
			this.txtLKdich.Size = new System.Drawing.Size(96, 20);
			this.txtLKdich.TabIndex = 9;
			this.txtLKdich.Text = "";
			this.txtLKdich.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtLKdich_KeyDown);
			this.txtLKdich.Validated += new System.EventHandler(this.txtLKdich_Validated);
			this.txtLKdich.TextChanged += new System.EventHandler(this.txtLKdich_TextChanged);
			// 
			// label15
			// 
			this.label15.Location = new System.Drawing.Point(640, 216);
			this.label15.Name = "label15";
			this.label15.Size = new System.Drawing.Size(48, 16);
			this.label15.TabIndex = 188;
			this.label15.Text = "LK đích:";
			// 
			// chkTulkn
			// 
			this.chkTulkn.Location = new System.Drawing.Point(608, 216);
			this.chkTulkn.Name = "chkTulkn";
			this.chkTulkn.Size = new System.Drawing.Size(16, 16);
			this.chkTulkn.TabIndex = 8;
			this.chkTulkn.CheckedChanged += new System.EventHandler(this.chkTulkn_CheckedChanged);
			// 
			// label14
			// 
			this.label14.Location = new System.Drawing.Point(560, 216);
			this.label14.Name = "label14";
			this.label14.Size = new System.Drawing.Size(48, 16);
			this.label14.TabIndex = 187;
			this.label14.Text = "Từ lkn:";
			// 
			// txtLKnguon
			// 
			this.txtLKnguon.Location = new System.Drawing.Point(472, 216);
			this.txtLKnguon.Name = "txtLKnguon";
			this.txtLKnguon.Size = new System.Drawing.Size(88, 20);
			this.txtLKnguon.TabIndex = 7;
			this.txtLKnguon.Text = "";
			this.txtLKnguon.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtLKnguon_KeyDown);
			this.txtLKnguon.Validated += new System.EventHandler(this.txtLKnguon_Validated);
			this.txtLKnguon.TextChanged += new System.EventHandler(this.txtLKnguon_TextChanged);
			// 
			// label11
			// 
			this.label11.Location = new System.Drawing.Point(392, 216);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(56, 16);
			this.label11.TabIndex = 186;
			this.label11.Text = "LK nguồn:";
			// 
			// dataGrid2
			// 
			this.dataGrid2.AlternatingBackColor = System.Drawing.Color.Navy;
			this.dataGrid2.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.dataGrid2.BackColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid2.BackgroundColor = System.Drawing.SystemColors.Control;
			this.dataGrid2.CaptionBackColor = System.Drawing.SystemColors.Control;
			this.dataGrid2.CaptionFont = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.dataGrid2.CaptionForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid2.DataMember = "";
			this.dataGrid2.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.dataGrid2.ForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid2.GridLineColor = System.Drawing.Color.Gainsboro;
			this.dataGrid2.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
			this.dataGrid2.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
			this.dataGrid2.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid2.LinkColor = System.Drawing.Color.Teal;
			this.dataGrid2.Location = new System.Drawing.Point(8, 344);
			this.dataGrid2.Name = "dataGrid2";
			this.dataGrid2.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
			this.dataGrid2.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid2.ReadOnly = true;
			this.dataGrid2.RowHeaderWidth = 10;
			this.dataGrid2.SelectionBackColor = System.Drawing.Color.CadetBlue;
			this.dataGrid2.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid2.Size = new System.Drawing.Size(792, 200);
			this.dataGrid2.TabIndex = 140;
			this.dataGrid2.CurrentCellChanged += new System.EventHandler(this.dataGrid2_CurrentCellChanged);
			// 
			// button1
			// 
			this.button1.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			this.button1.Image = ((System.Drawing.Bitmap)(resources.GetObject("button1.Image")));
			this.button1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.button1.Location = new System.Drawing.Point(352, 544);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(60, 25);
			this.button1.TabIndex = 191;
			this.button1.Text = "     &Xem";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// frmKetchuyen
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(792, 573);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.button1,
																		  this.listlkdich,
																		  this.listlknguon,
																		  this.txtLKdich,
																		  this.label15,
																		  this.chkTulkn,
																		  this.label14,
																		  this.txtLKnguon,
																		  this.label11,
																		  this.listKmcpdich4,
																		  this.listKmcpnguon4,
																		  this.txtKmcpdich4,
																		  this.label22,
																		  this.chkKmcpnguon4,
																		  this.label23,
																		  this.txtKmcpnguon4,
																		  this.label24,
																		  this.listKmcpdich3,
																		  this.listKmcpnguon3,
																		  this.txtKmcpdich3,
																		  this.label25,
																		  this.chkKmcpnguon3,
																		  this.label26,
																		  this.txtKmcpnguon3,
																		  this.label27,
																		  this.listkmcpdich2,
																		  this.listKmcpnguon2,
																		  this.txtKmcpdich2,
																		  this.label19,
																		  this.chkkmcpnguon2,
																		  this.label20,
																		  this.txtKmcpnguon2,
																		  this.label21,
																		  this.listngvudich,
																		  this.listngvunguon,
																		  this.listkmdich,
																		  this.listkmnguon,
																		  this.listsangtk,
																		  this.listtutk,
																		  this.stt,
																		  this.chkAll,
																		  this.butXoa,
																		  this.butKetthuc,
																		  this.cboKysl,
																		  this.butketchuyen,
																		  this.label18,
																		  this.dataGrid2,
																		  this.butMoi,
																		  this.butSua,
																		  this.butLuu,
																		  this.butHuy,
																		  this.butBoqua,
																		  this.butlaymau,
																		  this.butcoppy,
																		  this.txtDtthdich,
																		  this.label17,
																		  this.chkTuDtthn,
																		  this.label16,
																		  this.txtDtthnguon,
																		  this.label13,
																		  this.txtKmcpdich,
																		  this.label12,
																		  this.txtTenbtoan,
																		  this.label10,
																		  this.txtSangtk,
																		  this.chkKmcpn,
																		  this.label9,
																		  this.label8,
																		  this.txtKmcpnguon,
																		  this.txtTutk,
																		  this.txtSobtoan,
																		  this.label7,
																		  this.chkKetchuyen,
																		  this.label6,
																		  this.label5,
																		  this.label4,
																		  this.cbono_co,
																		  this.label3,
																		  this.txtNhomkmcpn,
																		  this.label2,
																		  this.label1,
																		  this.dataGrid1});
			this.Name = "frmKetchuyen";
			this.Text = "Kết chuyển cuối kỳ";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.Load += new System.EventHandler(this.frmKetchuyen_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.stt)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void butKetthuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}		
		private void frmKetchuyen_Load(object sender, System.EventArgs e)
		{				
			ena_object(false,true);
			format_sotien=a.format_sotien(0);
			
			listtutk.DisplayMember="STK";
			listtutk.TextMember="STK";
			listtutk.ValueMember="STK";

			listsangtk.DisplayMember="STK";
			listsangtk.TextMember="STK";
			listsangtk.ValueMember="STK";

			dttk=a.get_DMTaikhoan("").Tables[0];
			listtutk.DataSource=dttk;			
			listsangtk.DataSource=dttk;
			
			listlknguon.DisplayMember="LK";
			listlknguon.ValueMember="ID";

			listlkdich.DisplayMember="LK";
			listlkdich.ValueMember="ID";

			

			dtlk=a.get_DMLoaikhoan().Tables[0];
			listlknguon.DataSource=dtlk;			
			listlkdich.DataSource=dtlk;
			
			dtkhoanmuc=a.get_DMkhoanmuc("").Tables[0];
			listkmnguon.DisplayMember="TEN";
			listkmnguon.ValueMember="ID";

			listKmcpnguon2.DisplayMember="TEN";
			listKmcpnguon2.ValueMember="ID";

			listKmcpnguon3.DisplayMember="TEN";
			listKmcpnguon3.ValueMember="ID";

			listKmcpnguon4.DisplayMember="TEN";
			listKmcpnguon4.ValueMember="ID";

			listkmdich.DisplayMember="TEN";
			listkmdich.ValueMember="ID";

			listkmcpdich2.DisplayMember="TEN";
			listkmcpdich2.ValueMember="ID";

			listKmcpdich3.DisplayMember="TEN";
			listKmcpdich3.ValueMember="ID";

			listKmcpdich4.DisplayMember="TEN";
			listKmcpdich4.ValueMember="ID";

			sql="select * from a_nghiepvu where sudung=1";
			sql+=" order by stt";
			dtnv=a.get_data(sql).Tables[0];
			listngvunguon.DisplayMember="TEN";
			listngvunguon.ValueMember="ID";
			listngvunguon.DataSource=dtnv;

			listngvudich.DisplayMember="TEN";
			listngvudich.ValueMember="ID";
			listngvudich.DataSource=dtnv;

			this.currentRowBackBrush = new SolidBrush(Color.FromArgb(0,255, 255));
			this.disabledTextBrush = new SolidBrush(Color.FromArgb(255,0,0));
			this.currentRowFont = new Font(this.dataGrid1.Font.Name, this.dataGrid1.Font.Size, FontStyle.Regular);				

			cboKysl.ValueMember="MA";	
			cboKysl.DisplayMember="TEN";

			cbono_co.SelectedIndex=0;
			load_cboKysl();
			load_grid_ketchuyen(a.getrowbyid(dtKysl,"ma='"+cboKysl.SelectedValue.ToString()+"'")["id"].ToString().Trim());
			AddGridTableStyle();	
			AddGridTableStyle1();
			ref_text();
		}
		private void f_LoadKhoanmuc(ref LibList.List listKmuc,ref System.Data.DataTable dt_Dmkmuc,string s_IDLoaikhoanmuc) 		{ 			listKmuc.DisplayMember="TEN"; 			listKmuc.TextMember="MA"; 			listKmuc.ValueMember="TEN";  			dt_Dmkmuc=a.get_DMkhoanmuc(s_IDLoaikhoanmuc)!=null?a.get_DMkhoanmuc(s_IDLoaikhoanmuc).Tables[0]:null; 			listKmuc.DataSource=dt_Dmkmuc; 		}
		private void SetCellFormat(object sender, DataGridFormatCellEventArgs e)
		{
			try
			{
				bool discontinued = (bool) ((e.Column != 0) ? this.dataGrid1[e.Row, 0] : e.CurrentCellValue);
				if(e.Column > 0 && (bool)(this.dataGrid1[e.Row, 0]))//discontinued)
				{
					e.ForeBrush = this.disabledTextBrush;
				}
				else if(e.Column > 0 && e.Row == this.dataGrid1.CurrentRowIndex)
				{
					e.BackBrush = this.currentRowBackBrush;
					e.TextFont = this.currentRowFont;
				}
				if (decimal.Parse(dataGrid1[e.Row,3].ToString())!=0) e.ForeBrush=new SolidBrush(Color.Orange);
			}
			catch{}
		}
		private void RefreshRow(int row)
		{
			Rectangle rect = this.dataGrid1.GetCellBounds(row, 0);
			rect = new Rectangle(rect.Right, rect.Top, this.dataGrid1.Width, rect.Height);
			this.dataGrid1.Invalidate(rect);

			Rectangle rect2 = this.dataGrid2.GetCellBounds(row, 0);
			rect2 = new Rectangle(rect2.Right, rect2.Top, this.dataGrid2.Width, rect2.Height);
			this.dataGrid2.Invalidate(rect2);
		}
		private void BoolValueChanged(object sender, BoolValueChangedEventArgs e)
		{
			this.dataGrid1.EndEdit(this.dataGrid1.TableStyles[0].GridColumnStyles["Discontinued"],e.Row, false);
			RefreshRow(e.Row);
			this.dataGrid1.BeginEdit(this.dataGrid1.TableStyles[0].GridColumnStyles["Discontinued"],e.Row);

			this.dataGrid2.EndEdit(this.dataGrid2.TableStyles[0].GridColumnStyles["Discontinued"],e.Row, false);
			RefreshRow(e.Row);
			this.dataGrid2.BeginEdit(this.dataGrid2.TableStyles[0].GridColumnStyles["Discontinued"],e.Row);
		}
		private void AddGridTableStyle()
		{
			DataGridTableStyle ts =new DataGridTableStyle();			
			ts.MappingName = dtkc.TableName;
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.Gainsboro;
			ts.HeaderForeColor = Color.Blue;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
			ts.ReadOnly=false;
			ts.RowHeaderWidth=15;	
			ts.PreferredRowHeight=22;
					
			DataGridTextBoxColumn TextCol=new DataGridTextBoxColumn();			
			TextCol.MappingName = "id";
			TextCol.HeaderText = "";
			TextCol.Width = 0;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "stt";
			TextCol.HeaderText = "STT";
			TextCol.Width = 30;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			FormattableBooleanColumn discontinuedCol = new FormattableBooleanColumn();
			discontinuedCol.MappingName = "chon";
			discontinuedCol.HeaderText = "Kết chuyển";
			discontinuedCol.Width = 70;
			discontinuedCol.AllowNull = false;

			discontinuedCol.SetCellFormat += new FormatCellEventHandler(SetCellFormat);
			discontinuedCol.BoolValueChanged += new BoolValueChangedEventHandler(BoolValueChanged);
			ts.GridColumnStyles.Add(discontinuedCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "sobtoan";
			TextCol.HeaderText = "Sổ btoán";
			TextCol.NullText="";
			TextCol.Width = 50;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tenbt";
			TextCol.HeaderText = "tên btoán";
			TextCol.Width = 200;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tinhchat";
			TextCol.HeaderText = "Nợ/Có";
			TextCol.Width = 50;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tentutk";
			TextCol.HeaderText = "Từ tk";
			TextCol.Width = 50;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName ="tensangtk";
			TextCol.HeaderText = "Sang tk";
			TextCol.NullText="";
			TextCol.Width = 50;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tkmcpnguon";
			TextCol.HeaderText = "KMCP nguồn";
			TextCol.Width = 100;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tkmcpnguon2";
			TextCol.HeaderText = "KMCP nguồn 2";
			TextCol.Width = 100;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tkmcpnguon3";
			TextCol.HeaderText = "KMCP nguồn 3";
			TextCol.Width = 100;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tkmcpnguon4";
			TextCol.HeaderText = "KMCP nguồn 4";
			TextCol.Width = 100;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "nhomkmcpn";
			TextCol.HeaderText = "Nhóm KMCP nguồn";
			TextCol.Width = 70;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

//			TextCol=new DataGridTextBoxColumn();
//			TextCol.MappingName = "dtthnguon";
//			TextCol.HeaderText = "DTTH nguồn";
//			TextCol.Width = 70;
//			TextCol.NullText="";
//			ts.GridColumnStyles.Add(TextCol);
//			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tkmcpdich";
			TextCol.HeaderText = "KMCP đích";
			TextCol.Width = 100;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tkmcpdich2";
			TextCol.HeaderText = "KMCP đích 2";
			TextCol.Width = 100;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tkmcpdich3";
			TextCol.HeaderText = "KMCP đích 3";
			TextCol.Width = 100;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tkmcpdich4";
			TextCol.HeaderText = "KMCP đích 4";
			TextCol.Width = 100;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tlknguon";
			TextCol.HeaderText = "LK nguồn";
			TextCol.Width = 100;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tlkdich";
			TextCol.HeaderText = "LK đích";
			TextCol.Width = 100;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);	 

//			TextCol=new DataGridTextBoxColumn();
//			TextCol.MappingName = "tukmcpn";
//			TextCol.HeaderText = "Từ KMCP nguồn";
//			TextCol.Width = 90;
//			TextCol.NullText="";
//			ts.GridColumnStyles.Add(TextCol);
//			dataGrid1.TableStyles.Add(ts);
//
//			TextCol=new DataGridTextBoxColumn();
//			TextCol.MappingName = "dtthdich";
//			TextCol.HeaderText = "DTTH đích";
//			TextCol.Width = 60;
//			TextCol.NullText="";
//			ts.GridColumnStyles.Add(TextCol);
//			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "kysl";
			TextCol.HeaderText = "Kỳ số liệu";
			TextCol.Width = 60;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);			

//			TextCol=new DataGridTextBoxColumn();
//			TextCol.MappingName = "tulkn";
//			TextCol.HeaderText = "Từ LK nguồn";
//			TextCol.Width = 70;
//			TextCol.NullText="";
//			ts.GridColumnStyles.Add(TextCol);
//			dataGrid1.TableStyles.Add(ts);			
		}
		private void AddGridTableStyle1()
		{
			DataGridTableStyle ts =new DataGridTableStyle();			
			ts.MappingName = dtkc.TableName;
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.Gainsboro;
			ts.HeaderForeColor = Color.Blue;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
			ts.ReadOnly=false;
			ts.RowHeaderWidth=15;	
			ts.PreferredRowHeight=22;
						
			DataGridTextBoxColumn TextCol=new DataGridTextBoxColumn();	

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "idct";
			TextCol.HeaderText = "";
			TextCol.Width = 0;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "stt";
			TextCol.HeaderText = "STT";
			TextCol.Width = 30;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "lk";
			TextCol.HeaderText = "Loại Khoản";
			TextCol.Width = 50;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "noidung";
			TextCol.HeaderText = "Nội dung";
			TextCol.Width = 200;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "stknoa";
			TextCol.HeaderText = "TK Nợ";
			TextCol.Width = 80;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "stkmtmno";
			TextCol.HeaderText = "MTM Nợ";
			TextCol.Width = 50;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tenkmno";
			TextCol.HeaderText = "KM Nợ";
			TextCol.Width = 100;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "stkcoa";
			TextCol.HeaderText = "TK Có";
			TextCol.Width = 80;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "stkmtmco";
			TextCol.HeaderText = "MTM Có";
			TextCol.Width = 100;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tenkmco";
			TextCol.HeaderText = "KM Có";
			TextCol.Width = 50;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tenpt";
			TextCol.HeaderText = "Phân tích";
			TextCol.Width = 100;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "mangoaite";
			TextCol.HeaderText = "Ngoại tệ";
			TextCol.Width = 30;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tygia";
			TextCol.HeaderText = "Tỷ giá";
			TextCol.Width = 50;
			TextCol.NullText="";
			TextCol.Format="###,###,###";
			TextCol.Alignment=HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "nguyente";
			TextCol.HeaderText = "Nguyên tệ";
			TextCol.Width = 80;
			TextCol.NullText="";
			TextCol.Format=format_sotien;
			TextCol.Alignment=HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "stien";
			TextCol.HeaderText = "Số tiền";
			TextCol.Width = 100;
			TextCol.NullText="";
			TextCol.Format=format_sotien;
			TextCol.Alignment=HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tonghop";
			TextCol.HeaderText = "";
			TextCol.Width = 0;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);
		}

		public void load_gridct()
		{
			getthang();
			dataGrid2.DataSource=null;
			sql="select to_number(a.id) as id,to_number(a.idct) as idct,a.stt,a.lk,a.noidung,a.tknoa,a.tkcoa,a.kmno,a.kmno2,a.kmno3,a.kmno4,a.kmco,a.kmco2,a.kmco3,a.kmco4,a.mtmno,a.mtmco,";
			sql+="a.stien,a.nguyente,a.ngoaite,a.tygia,n.ma as mangoaite,a.tonghop,a.mapt,a.ctgs,b.lk as tenlk,";
			sql+="c.stk as stknoa,d.stk as stkcoa,";
			sql+="nvl(e.stk,' ') as stkmtmno,nvl(f.stk,' ') as stkmtmco,nvl(g.ten,' ') as tenpt,";
			sql+="nvl(h.ten,' ') as tenkmno,nvl(i.ten,' ') as tenkmco,";
			sql+="c.mlns as mlnsno,c.ctmlns as ctmlnsno,d.mlns as mlnsco,d.ctmlns as ctmlnsco,";
			sql+="c.loaikm as loaikmno,d.loaikm as loaikmco,a.capphat,j.ten as tencapphat,a.thangqt ";
			sql+=" from a_ctct"+s_mmyy.Substring(2)+" a left join a_dmlk b on a.lk=b.id ";
			sql+=" inner join a_ct"+s_mmyy.Substring(2)+" ct on ct.id=a.idct";
			sql+=" left join a_dmtk c on a.tknoa=c.id ";
			sql+=" left join a_dmtk d on a.tkcoa=d.id ";
			sql+=" left join a_dmch e on a.mtmno=e.id ";
			sql+=" left join a_dmch f on a.mtmco=f.id ";
			sql+=" left join a_phantich g on a.mapt=g.id ";
			sql+=" left join a_dmkhoanmuc h on a.kmno=h.id ";
			sql+=" left join a_dmkhoanmuc i on a.kmco=i.id ";
			sql+=" left join a_dmcapphat j on a.capphat=j.id ";
			sql+=" left join a_dmngoaite n on a.ngoaite=n.id ";
			sql+=" where ct.chucnang=6 and ct.lctug=37 and ct.thanggs='"+s_mmt+"'";
			sql+=" order by a.stt";
			dtct=a.get_data(sql).Tables[0];
			dataGrid2.DataSource=dtct;
		}
		private void hidelist()
		{
			if(!listtutk.Focused) listtutk.Hide();
			if(!listsangtk.Focused) listsangtk.Hide();
			if(!listlknguon.Focused) listlknguon.Hide();
			if(!listlkdich.Focused) listlkdich.Hide();
			if(!listkmnguon.Focused) listkmnguon.Hide();
			if(!listkmdich.Focused) listkmdich.Hide();
			if(!listngvunguon.Focused) listngvunguon.Hide();
			if(!listngvudich.Focused) listngvudich.Hide();
			if(!listKmcpnguon2.Focused) listKmcpnguon2.Hide();
			if(!listKmcpnguon3.Focused) listKmcpnguon3.Hide();
			if(!listKmcpnguon4.Focused) listKmcpnguon4.Hide();
			if(!listkmcpdich2.Focused) listkmcpdich2.Hide();
			if(!listKmcpdich3.Focused) listKmcpdich3.Hide();
			if(!listKmcpdich4.Focused) listKmcpdich4.Hide();
		}
		
		private void Filter_List(LibList.List listDulieu,string s_Dkloc,string s_Tenfield_1,string s_Tenfield_2) 		{ 			try 			{ 				string s_Dieukien=s_Tenfield_1.Trim()+" like '%"+s_Dkloc.Trim()+"%'"; 				if (s_Tenfield_2.Trim()!="") s_Dieukien+=" or "+s_Tenfield_2.Trim()+" like '%"+s_Dkloc.Trim()+"%'"; 				CurrencyManager cm= (CurrencyManager)BindingContext[listDulieu.DataSource]; 				System.Data.DataView dv=(System.Data.DataView)cm.List; 				dv.RowFilter=s_Dieukien; 			} 			catch{} 		}

		private void Filter_stk(string ma,LibList.List list)
		{
			CurrencyManager cm= (CurrencyManager)BindingContext[list.DataSource];
			DataView dv=(DataView)cm.List;
			sql="stk like '"+ma.Trim()+"%' or ttk like '%"+ma.Trim()+"%'";
			dv.RowFilter=sql;
		}			
		private void load_cboKysl()
		{
			dtKysl=a.get_data("select id,ten||' Năm "+s_yyyy+"' as ten,ma from "+a.user+".a_dmkybc order by id").Tables[0];
			cboKysl.DataSource=dtKysl;
			
		}
		public void load_grid_ketchuyen(string kysl)
		{
			sql="select a.id as id,a.stt as stt,a.ketchuyen as ketchuyen,a.sobtoan as sobtoan,";
			sql+=" a.tenbt as tenbt,a.tinhchat as tinhchat,b.ten as tentc,";
			sql+=" a.tutk as tutk,c.stk as tentutk,a.sangtk as sangtk,d.stk as tensangtk,";
			sql+=" a.tukmcpn,a.tukmcpn2,a.tukmcpn3,a.tukmcpn4,a.tudtthn,";
			sql+=" a.kmcpnguon as akmcpnguon,a.kmcpnguon2 as akmcpnguon2,a.kmcpnguon3 as akmcpnguon3,a.kmcpnguon4 as akmcpnguon4,";
			sql+=" kmng.ma as kmcpnguon,kmng2.ma as kmcpnguon2,kmng3.ma as kmcpnguon3,kmng4.ma as kmcpnguon4,";
			sql+=" kmng.ten as tkmcpnguon,kmng2.ten as tkmcpnguon2,kmng3.ten as tkmcpnguon3,kmng4.ten as tkmcpnguon4,";
			sql+=" a.nhomkmcpn as nhomkmcpn,a.dtthnguon as dtthnguon,";
			sql+=" a.kmcpdich as akmcpdich,a.kmcpdich2 as akmcpdich2,a.kmcpdich3 as akmcpdich3,a.kmcpdich4 as akmcpdich4,";
			sql+=" kmd.ma as kmcpdich,kmd2.ma as kmcpdich2,kmd3.ma as kmcpdich3,kmd4.ma as kmcpdich4,";
			sql+=" kmd.ten as tkmcpdich,kmd2.ten as tkmcpdich2,kmd3.ten as tkmcpdich3,kmd4.ten as tkmcpdich4,";
			sql+=" a.tukmcpn as tukmcpn,a.tudtthn as tudtthn,a.dtthdich as dtthdich,";
			sql+=" a.kysl as kysl,a.tulkn as tulkn,lkd.lk as lkdich,lkng.lk as lknguon,lkd.tlk as tlkdich,lkng.tlk as tlknguon ";
			sql+=" from "+a.user+".a_ctkc"+s_yy+" a ";
			sql+=" left join "+a.user+".a_dmtctk b on b.id=a.tinhchat";
			sql+=" left join "+a.user+".a_dmtk c on c.id=a.tutk ";
			sql+=" left join "+a.user+".a_dmkhoanmuc kmng on a.kmcpnguon=kmng.id";
			sql+=" left join "+a.user+".a_dmkhoanmuc kmng2 on a.kmcpnguon2=kmng2.id";
			sql+=" left join "+a.user+".a_dmkhoanmuc kmng3 on a.kmcpnguon3=kmng3.id";
			sql+=" left join "+a.user+".a_dmkhoanmuc kmng4 on a.kmcpnguon4=kmng4.id";
			sql+=" left join "+a.user+".a_dmkhoanmuc kmd on a.kmcpdich=kmd.id";
			sql+=" left join "+a.user+".a_dmkhoanmuc kmd2 on a.kmcpdich2=kmd2.id";
			sql+=" left join "+a.user+".a_dmkhoanmuc kmd3 on a.kmcpdich3=kmd3.id";
			sql+=" left join "+a.user+".a_dmkhoanmuc kmd4 on a.kmcpdich4=kmd4.id";
			sql+=" left join "+a.user+".a_dmlk lkng on a.lknguon=lkng.id ";
			sql+=" left join "+a.user+".a_dmlk lkd on a.lkdich=lkd.id ";
			sql+=" left join "+a.user+".a_dmtk d on d.id=a.sangtk where kysl="+kysl+" order by stt";			
			dtkc=a.get_data(sql).Tables[0];
			dtkc.Columns.Add(new DataColumn("chon",typeof(bool)));
			foreach(DataRow r in dtkc.Rows) r["chon"]=r["ketchuyen"].ToString()=="1"?true:false;
			dataGrid1.DataSource=dtkc;
				
		}
		public DataSet DS_ketchuyen(string kysl)
		{
			DataSet dskc=new DataSet();
			sql="select a.id as id,a.stt as stt,a.ketchuyen as ketchuyen,a.sobtoan as sobtoan,";
			sql+=" a.tenbt as tenbt,a.tinhchat as tinhchat,b.ten as tentc,";
			sql+=" a.tutk as tutk,c.stk as tentutk,a.sangtk as sangtk,d.stk as tensangtk,";
			sql+=" a.tukmcpn,a.tukmcpn2,a.tukmcpn3,a.tukmcpn4,a.tudtthn,";
			sql+=" a.kmcpnguon as akmcpnguon,a.kmcpnguon2 as akmcpnguon2,a.kmcpnguon3 as akmcpnguon3,a.kmcpnguon4 as akmcpnguon4,";
			sql+=" kmng.ma as kmcpnguon,kmng2.ma as kmcpnguon2,kmng3.ma as kmcpnguon3,kmng4.ma as kmcpnguon4,";
			sql+=" kmng.ten as tkmcpnguon,kmng2.ten as tkmcpnguon2,kmng3.ten as tkmcpnguon3,kmng4.ten as tkmcpnguon4,";
			sql+=" a.nhomkmcpn as nhomkmcpn,a.dtthnguon as dtthnguon,";
			sql+=" a.kmcpdich as akmcpdich,a.kmcpdich2 as akmcpdich2,a.kmcpdich3 as akmcpdich3,a.kmcpdich4 as akmcpdich4,";
			sql+=" kmd.ma as kmcpdich,kmd2.ma as kmcpdich2,kmd3.ma as kmcpdich3,kmd4.ma as kmcpdich4,";
			sql+=" kmd.ten as tkmcpdich,kmd2.ten as tkmcpdich2,kmd3.ten as tkmcpdich3,kmd4.ten as tkmcpdich4,";
			sql+=" a.tukmcpn as tukmcpn,a.tudtthn as tudtthn,a.dtthdich as dtthdich,";
			sql+=" a.kysl as kysl,a.tulkn as tulkn,lkd.lk as lkdich,lkng.lk as lknguon,lkd.tlk as tlkdich,lkng.tlk as tlknguon ";
			sql+=" from "+a.user+".a_ctkc"+s_yy+" a ";
			sql+=" left join "+a.user+".a_dmtctk b on b.id=a.tinhchat";
			sql+=" left join "+a.user+".a_dmtk c on c.id=a.tutk ";
			sql+=" left join "+a.user+".a_dmkhoanmuc kmng on a.kmcpnguon=kmng.id";
			sql+=" left join "+a.user+".a_dmkhoanmuc kmng2 on a.kmcpnguon2=kmng2.id";
			sql+=" left join "+a.user+".a_dmkhoanmuc kmng3 on a.kmcpnguon3=kmng3.id";
			sql+=" left join "+a.user+".a_dmkhoanmuc kmng4 on a.kmcpnguon4=kmng4.id";
			sql+=" left join "+a.user+".a_dmkhoanmuc kmd on a.kmcpdich=kmd.id";
			sql+=" left join "+a.user+".a_dmkhoanmuc kmd2 on a.kmcpdich2=kmd2.id";
			sql+=" left join "+a.user+".a_dmkhoanmuc kmd3 on a.kmcpdich3=kmd3.id";
			sql+=" left join "+a.user+".a_dmkhoanmuc kmd4 on a.kmcpdich4=kmd4.id";
			sql+=" left join "+a.user+".a_dmlk lkng on a.lknguon=lkng.id ";
			sql+=" left join "+a.user+".a_dmlk lkd on a.lknguon=lkd.id ";
			sql+=" left join "+a.user+".a_dmtk d on d.id=a.sangtk where kysl="+kysl+" order by stt";			
			try
			{
				dskc=a.get_data(sql).Copy();
			}
			catch{dskc=null;};
			if(dskc.Tables[0].Rows.Count<0||dskc==null)
				return null;
			else
				return dskc;

//			dtkc.Columns.Add(new DataColumn("chon",typeof(bool)));
//			foreach(DataRow r in dtkc.Rows) r["chon"]=r["ketchuyen"].ToString()=="1"?true:false;
//			dataGrid1.DataSource=dtkc;
				
		}
		private void ena_object(bool ena, bool moi)
		{
			stt.Enabled=txtDtthdich.Enabled=txtDtthnguon.Enabled=txtKmcpdich.Enabled=txtKmcpnguon.Enabled=txtLKdich.Enabled=txtLKnguon.Enabled=txtNhomkmcpn.Enabled=txtSangtk.Enabled=txtSobtoan.Enabled=txtTenbtoan.Enabled=txtTutk.Enabled=ena;
			cbono_co.Enabled=chkKetchuyen.Enabled=chkKmcpn.Enabled=chkkmcpnguon2.Enabled=chkKmcpnguon3.Enabled=chkKmcpnguon4.Enabled=chkTuDtthn.Enabled=chkTulkn.Enabled=ena;
			txtKmcpnguon2.Enabled=txtKmcpdich2.Enabled=txtKmcpnguon3.Enabled=txtKmcpdich3.Enabled=txtKmcpnguon4.Enabled=txtKmcpdich4.Enabled=ena;
			butXoa.Enabled=butLuu.Enabled=butBoqua.Enabled=ena;
			chkAll.Enabled=butSua.Enabled=butHuy.Enabled=butKetthuc.Enabled=!ena;
	
			if(moi==true)
			{
				txtDtthdich.Text=txtDtthnguon.Text=txtKmcpdich.Text=txtKmcpnguon.Text=txtLKdich.Text=txtLKnguon.Text=txtNhomkmcpn.Text=txtSangtk.Text=txtSobtoan.Text=txtTenbtoan.Text=txtTutk.Text="";
				cbono_co.SelectedIndex=0;
				chkKetchuyen.Checked=chkKmcpn.Checked=chkkmcpnguon2.Checked=chkKmcpnguon3.Checked=chkKmcpnguon4.Checked=chkTuDtthn.Checked=chkTulkn.Checked=false;
				txtKmcpnguon2.Text=txtKmcpdich2.Text=txtKmcpnguon3.Text=txtKmcpdich3.Text=txtKmcpnguon4.Text=txtKmcpdich4.Text="";
			}
		}

		private void butMoi_Click(object sender, System.EventArgs e)
		{
			try
			{
				stt.Value=decimal.Parse(a.get_data("select max(stt) from "+a.user+".a_ctkc"+s_yy+"").Tables[0].Rows[0][0].ToString())+1;
			}
			catch{stt.Value=1;}
			l_id=0;			
			ena_object(true,true);
			stt.Focus();
		}

		private void butBoqua_Click(object sender, System.EventArgs e)
		{
			ref_text();
			ena_object(false,false);
		}

		private void butSua_Click(object sender, System.EventArgs e)
		{
			if (dtkc.Rows.Count==0) return;
			l_id=int.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString());
			ena_object(true,false);
			stt.Focus();
		}
		private bool kiemtra()
		{
			if (txtSobtoan.Text=="")
			{
				MessageBox.Show("Yêu cầu nhập số bút toán !",a.Msg);
				txtSobtoan.Focus();
				return false;
			}
			else if (txtTenbtoan.Text=="")
			{
				MessageBox.Show("Yêu cầu nhập tên bút toán !",a.Msg);
				txtTenbtoan.Focus();
				return false;
			}
			else if (txtTutk.Text=="")
			{
				MessageBox.Show("Yêu cầu nhập Tài khoản gốc kết chuyển !",a.Msg);
				txtTutk.Focus();
				return false;
			}
			else if (txtSangtk.Text=="")
			{
				MessageBox.Show("Yêu cầu nhập Tài khoản kết chuyển sang !",a.Msg);
				txtSangtk.Focus();
				return false;
			}
			return true;
		}
		private void butLuu_Click(object sender, System.EventArgs e)
		{
			
			/*if (!kiemtra()) return ;
			if (l_id==0)
			{
				try
				{
					l_id=int.Parse(a.get_data("select max(id) from "+a.user+".a_ctkc"+s_yy+"").Tables[0].Rows[0][0].ToString())+1;
				}
				catch{l_id=1;}
			}
			int i_idtutk=0,i_idsangtk=0, i_tinhchattk=0, i_kmcpnguon=0,i_kmcpnguon2=0,i_kmcpnguon3=0,i_kmcpnguon4=0;
			int i_kmcpdich=0,i_kmcpdich2=0,i_kmcpdich3=0,i_kmcpdich4=0,i_lknguon=0,i_lkdich=0,i_dtth=0,i_dtthdich=0;
			if (txtTutk.Text.Trim()!="") i_idtutk=Convert.ToInt32(a.getrowbyid(dttk,"stk='"+txtTutk.Text.Trim()+"'")["id"].ToString().Trim());
			if (txtSangtk.Text.Trim()!="") i_idsangtk=Convert.ToInt32( a.getrowbyid(dttk,"stk='"+txtSangtk.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtKmcpnguon.Text.Trim()!="") i_kmcpnguon=Convert.ToInt32( a.getrowbyid(dtkhoanmuc,"ma='"+txtKmcpnguon.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtKmcpnguon2.Text.Trim()!="") i_kmcpnguon2=Convert.ToInt32( a.getrowbyid(dtkhoanmuc,"ma='"+txtKmcpnguon2.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtKmcpnguon3.Text.Trim()!="") i_kmcpnguon3=Convert.ToInt32( a.getrowbyid(dtkhoanmuc,"ma='"+txtKmcpnguon3.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtKmcpnguon4.Text.Trim()!="") i_kmcpnguon4=Convert.ToInt32( a.getrowbyid(dtkhoanmuc,"ma='"+txtKmcpnguon4.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtKmcpdich.Text.Trim()!="") i_kmcpdich=Convert.ToInt32( a.getrowbyid(dtkhoanmuc,"ma='"+txtKmcpdich.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtKmcpdich2.Text.Trim()!="") i_kmcpdich2=Convert.ToInt32( a.getrowbyid(dtkhoanmuc,"ma='"+txtKmcpdich2.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtKmcpdich3.Text.Trim()!="") i_kmcpdich3=Convert.ToInt32( a.getrowbyid(dtkhoanmuc,"ma='"+txtKmcpdich3.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtKmcpdich4.Text.Trim()!="") i_kmcpdich4=Convert.ToInt32( a.getrowbyid(dtkhoanmuc,"ma='"+txtKmcpdich4.Text.Trim()+"'")["id"].ToString().Trim());		
			if(txtDtthnguon.Text.Trim()!="") i_dtth=int.Parse(txtDtthnguon.Text);
			if(txtDtthdich.Text.Trim()!="") i_dtthdich=int.Parse(txtDtthdich.Text);
			if(txtLKnguon.Text.Trim()!="") i_lknguon=Convert.ToInt32(a.getrowbyid(dtlk,"lk='"+txtLKnguon.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtLKdich.Text.Trim()!="") i_lkdich=Convert.ToInt32(a.getrowbyid(dtlk,"lk='"+txtLKdich.Text.Trim()+"'")["id"].ToString().Trim());
			if((cbono_co.SelectedIndex)==0)
				i_tinhchattk=1;
			else if((cbono_co.SelectedIndex)==1)
				i_tinhchattk=2;
			else i_tinhchattk=0;
			if (!a.upd_ctkc(l_id,stt.Value,s_yy,(chkKetchuyen.Checked)?1:0,txtSobtoan.Text,txtTenbtoan.Text,i_tinhchattk,i_idtutk,i_idsangtk,i_kmcpnguon,txtNhomkmcpn.Text,i_dtth,(chkKmcpn.Checked)?1:0,i_kmcpnguon2,i_kmcpnguon3,i_kmcpnguon4,i_kmcpdich,i_kmcpdich2,i_kmcpdich3,i_kmcpdich4,(chkTuDtthn.Checked)?1:0,i_dtthdich,Convert.ToInt32(cboKysl.SelectedValue.ToString()),i_lknguon,(chkTulkn.Checked)?1:0,i_lkdich,i_userId,DateTime.Now))
			{
				MessageBox.Show("Không cập nhật thông tin "+this.Text.Trim()+" !",a.Msg);
				return;
			}
			load_grid_ketchuyen(cboKysl.SelectedValue.ToString());
			ref_text();
			ena_object(false,false);*/

			if (!kiemtra()) return ;
			if (l_id==0)
			{
				try
				{
					l_id=int.Parse(a.get_data("select max(id) from "+a.user+".a_ctkc"+s_yy+"").Tables[0].Rows[0][0].ToString())+1;
				}
				catch{l_id=1;}
			}
			int i_idtutk=0,i_idsangtk=0, i_tinhchattk=0;			
			string s_kmcpnguon="",s_kmcpnguon2="",s_kmcpnguon3="",s_kmcpnguon4="",s_kmcpdich="",s_kmcpdich2="";
			string s_kmcpdich3="",s_kmcpdich4="",s_lknguon="",s_lkdich="",s_dtthn="",s_dtthdich="";
			if (txtTutk.Text.Trim()!="") i_idtutk=Convert.ToInt32(a.getrowbyid(dttk,"stk='"+txtTutk.Text.Trim()+"'")["id"].ToString().Trim());
			if (txtSangtk.Text.Trim()!="") i_idsangtk=Convert.ToInt32( a.getrowbyid(dttk,"stk='"+txtSangtk.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtKmcpnguon.Text.Trim()!="") s_kmcpnguon =id_text(dtkhoanmuc,txtKmcpnguon.Text);
			if(txtKmcpnguon2.Text.Trim()!="") s_kmcpnguon2=id_text(dtkhoanmuc,txtKmcpnguon2.Text);
			if(txtKmcpnguon3.Text.Trim()!="") s_kmcpnguon3=id_text(dtkhoanmuc,txtKmcpnguon3.Text);
			if(txtKmcpnguon4.Text.Trim()!="") s_kmcpnguon4=id_text(dtkhoanmuc,txtKmcpnguon4.Text);
			if(txtKmcpdich.Text.Trim()!="") s_kmcpdich=id_text(dtkhoanmuc,txtKmcpdich.Text);
			if(txtKmcpdich2.Text.Trim()!="") s_kmcpdich2=id_text(dtkhoanmuc,txtKmcpdich2.Text);
			if(txtKmcpdich3.Text.Trim()!="") s_kmcpdich3=id_text(dtkhoanmuc,txtKmcpdich3.Text);
			if(txtKmcpdich4.Text.Trim()!="") s_kmcpdich4=id_text(dtkhoanmuc,txtKmcpdich4.Text);		
			if(txtDtthnguon.Text.Trim()!="") s_dtthn=txtDtthnguon.Text;
			if(txtDtthdich.Text.Trim()!="") s_dtthdich=txtDtthdich.Text;
			if(txtLKnguon.Text.Trim()!="") s_lknguon=id_lk(dtlk,txtLKnguon.Text);
			if(txtLKdich.Text.Trim()!="") s_lkdich=id_lk(dtlk,txtLKdich.Text);
			if((cbono_co.SelectedIndex)==0)
				i_tinhchattk=1;
			else if((cbono_co.SelectedIndex)==1)
				i_tinhchattk=2;
			else i_tinhchattk=0;
			if (!a.upd_ctkc(l_id,stt.Value,s_yy,(chkKetchuyen.Checked)?1:0,txtSobtoan.Text,txtTenbtoan.Text,i_tinhchattk,i_idtutk,i_idsangtk,s_kmcpnguon,txtNhomkmcpn.Text,s_dtthn,(chkKmcpn.Checked)?1:0,s_kmcpnguon2,s_kmcpnguon3,s_kmcpnguon4,s_kmcpdich,s_kmcpdich2,s_kmcpdich3,s_kmcpdich4,(chkTuDtthn.Checked)?1:0,s_dtthdich,Convert.ToInt32(cboKysl.SelectedValue.ToString()),s_lknguon,(chkTulkn.Checked)?1:0,s_lkdich,i_userId,DateTime.Now))
			{
				MessageBox.Show("Không cập nhật thông tin "+this.Text.Trim()+" !",a.Msg);
				return;
			}
			load_grid_ketchuyen(cboKysl.SelectedValue.ToString());
			ref_text();
			ena_object(false,false);
		}
		public string id_text(DataTable dttb, string chuoi)
		{
			string s_IDdm="";
			try
			{
				if (chuoi!="")
				{					
					for(int i=0;i<=dttb.Rows.Count;i++)
					{
						chuoi=chuoi.Replace(",","','");
						System.Data.DataRow dr=dttb.Select("ma in ('"+chuoi+"')","ma")[i];
						s_IDdm+=dr["id"].ToString()+",";
					}
					if (s_IDdm.Substring(s_IDdm.Length-1,1)==",") s_IDdm=s_IDdm.Substring(0,s_IDdm.Length-1);
				}
			}
			catch{}	;
			return s_IDdm;
		}
		public string id_lk(DataTable dttb, string chuoi)
		{
			string s_IDdm="";
			try
			{
				if (chuoi!="")
				{					
					for(int i=0;i<dttb.Rows.Count;i++)
					{ 
						chuoi=chuoi.Replace(",","','");
						System.Data.DataRow dr=dttb.Select("lk in ('"+chuoi+"')","lk")[i];
						s_IDdm+=dr["id"].ToString()+",";
					}
					if (s_IDdm.Substring(s_IDdm.Length-1,1)==",") s_IDdm=s_IDdm.Substring(0,s_IDdm.Length-1);
				}
			}
			catch{}	;
			return s_IDdm;
		}

		private void txtTutk_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listtutk.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listtutk.Visible)	listtutk.Focus();
				else SendKeys.Send("{Tab}");
			}		
			else if (e.KeyCode==Keys.Escape) listtutk.Hide();
		}

		private void txtTutk_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtTutk)
			{
				Filter_List(listtutk,txtTutk.Text.Trim(),"stk","");
				listtutk.BrowseToDmtk(txtTutk,txtTutk,txtSangtk,txtTutk.Location.X,txtTutk.Location.Y+txtTutk.Height,500,txtTutk.Height,100);
			}
		}

		private void txtTutk_Validated(object sender, System.EventArgs e)
		{
			DataRow r=a.getrowbyid(dttk,"stk='"+txtTutk.Text+"'");
			txtTutk.Text=(r!=null)?r["stk"].ToString():"";		
			hidelist();
		}

		private void txtSangtk_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listsangtk.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listsangtk.Visible)	listsangtk.Focus();
				else SendKeys.Send("{Tab}");
			}		
			else if (e.KeyCode==Keys.Escape) listsangtk.Hide();
		}

		private void txtSangtk_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtSangtk)
			{
				//Filter_stk(txtSangtk.Text,listtkno);
				Filter_List(listsangtk,txtSangtk.Text.Trim(),"stk","");
				listsangtk.BrowseToDmtk(txtSangtk,txtSangtk,txtLKnguon,txtSangtk.Location.X,txtSangtk.Location.Y+txtSangtk.Height,500,txtSangtk.Height,100);
			}
		}

		private void txtSangtk_Validated(object sender, System.EventArgs e)
		{
			DataRow r=a.getrowbyid(dttk,"stk='"+txtSangtk.Text+"'");
			txtSangtk.Text=(r!=null)?r["stk"].ToString():"";		
			hidelist();
		}

		private void ref_text()
		{
			try
			{
				l_id=int.Parse(dataGrid1[dataGrid1.CurrentRowIndex,0].ToString() );
				DataRow r =a.getrowbyid(dtkc,"id="+l_id);
				if(r!=null)
				{	
					stt.Value=decimal.Parse(r["stt"].ToString());
					chkKetchuyen.Checked=r["ketchuyen"].ToString().Trim()=="1";
					txtSobtoan.Text=r["sobtoan"].ToString().Trim();
					txtTenbtoan.Text=r["tenbt"].ToString().Trim();
					cbono_co.Text=r["tentc"].ToString().Trim();
					txtTutk.Text=r["tentutk"].ToString().Trim()!=""?r["tentutk"].ToString().Trim():"";
					txtSangtk.Text=r["tensangtk"].ToString().Trim()!=""?r["tensangtk"].ToString().Trim():"";
					txtLKnguon.Text=r["lknguon"].ToString().Trim()!=""?r["lknguon"].ToString().Trim():"";
					chkTulkn.Checked=r["tulkn"].ToString().Trim()=="1";
					txtLKdich.Text=r["lkdich"].ToString().Trim()!=""?r["lkdich"].ToString().Trim():"";
					txtNhomkmcpn.Text=r["nhomkmcpn"].ToString().Trim();
					txtKmcpnguon.Text=int.Parse(r["akmcpnguon"].ToString().Trim())!=0?r["kmcpnguon"].ToString().Trim():"";
					txtKmcpnguon2.Text=int.Parse(r["akmcpnguon2"].ToString().Trim())!=0?r["kmcpnguon2"].ToString().Trim():"";
					txtKmcpnguon3.Text=int.Parse(r["akmcpnguon3"].ToString().Trim())!=0?r["kmcpnguon3"].ToString().Trim():"";
					txtKmcpnguon4.Text=int.Parse(r["akmcpnguon4"].ToString().Trim())!=0?r["kmcpnguon4"].ToString().Trim():"";
					chkKmcpn.Checked=r["tukmcpn"].ToString().Trim()=="1";
					chkkmcpnguon2.Checked=r["tukmcpn2"].ToString().Trim()=="1";
					chkKmcpnguon3.Checked=r["tukmcpn3"].ToString().Trim()=="1";
					chkKmcpnguon4.Checked=r["tukmcpn4"].ToString().Trim()=="1";
					txtKmcpdich.Text=int.Parse(r["akmcpdich"].ToString().Trim())!=0?r["kmcpdich"].ToString().Trim():"";
					txtKmcpdich2.Text=int.Parse(r["akmcpdich2"].ToString().Trim())!=0?r["kmcpdich2"].ToString().Trim():"";
					txtKmcpdich3.Text=int.Parse(r["akmcpdich3"].ToString().Trim())!=0?r["kmcpdich3"].ToString().Trim():"";
					txtKmcpdich4.Text=int.Parse(r["akmcpdich4"].ToString().Trim())!=0?r["kmcpdich4"].ToString().Trim():"";
					txtDtthnguon.Text=r["dtthnguon"].ToString().Trim()!=""?r["dtthnguon"].ToString().Trim():"";
					chkTuDtthn.Checked=r["tudtthn"].ToString().Trim()=="1";
					txtDtthdich.Text=int.Parse(r["dtthdich"].ToString().Trim())!=0?r["dtthdich"].ToString().Trim():"";
				}
			}
			catch{};			
		}
		private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
		{
			ref_text();
		}

		private void butHuy_Click(object sender, System.EventArgs e)
		{
//			if (dtkc.Rows.Count==1)
//			{
//				MessageBox.Show("Không cho phép hủy ?",a.Msg);
//				return;
//			}	
			if(DS_ketchuyen(cboKysl.SelectedValue.ToString()).Tables[0].Rows.Count>0)
			{
				if (MessageBox.Show("Đồng ý hủy thông tin này !",a.Msg,MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
				{					
					a.execute_data("delete from "+a.user+".a_ctkc"+s_yy+" where id in ("+long.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString())+")");
					load_grid_ketchuyen(cboKysl.SelectedValue.ToString());
				}
			}
			else
				MessageBox.Show("Không có chứng từ để hủy");
		}
		private void chkAll_CheckedChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==chkAll)				
			foreach(DataRow r in dtkc.Rows) 
			{
				
				r["chon"]=(chkAll.Checked)?true:false;
			}
			string dk="";
			if(chkAll.Checked)
				dk="ketchuyen=1";
			else
				dk="ketchuyen=0";
			string sKysl="";
			if(int.Parse(cboKysl.SelectedValue.ToString())<=12)
				sKysl=cboKysl.SelectedValue.ToString().Substring(1,1);
			else
				sKysl=cboKysl.SelectedValue.ToString();
			a.get_data("update "+a.user+".a_ctkc"+s_yy+" set "+dk+" where kysl='"+sKysl+"'");
		}
		private void cboKysl_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(this.ActiveControl!=cboKysl) return;
			try
			{
				load_grid_ketchuyen(cboKysl.SelectedValue.ToString());	
				ref_text();	
				load_gridct();
			}
			catch{};
		}

		private DataSet chungtuketchuyen(string mm,string yy,string tinhchat, string stk, string idlk, string idkmcp,string idkmcp2, string idkmcp3, string idkmcp4, 
			string iddtth, string  lkdich, string kmcpdich,string kmcpdich2,string kmcpdich3,string kmcpdich4,string dtthdich)
		{
			sql = "select ";
			string stienno="",stienco="";
			if(mm=="Q1"||mm=="03") 
			{
				stienno="sum(a.sdno04)";
				stienco="sum(a.sdco04)";
			}
			else if(mm=="Q2"||mm=="06")
			{
				stienno="sum(a.sdno07)";
				stienco="sum(a.sdco07)";
			}
			else if(mm=="Q3" || mm=="09")
			{
				stienno="sum(a.sdno10)";
				stienco="sum(a.sdco10)";
			}
			else if(mm=="Q4" || mm=="12")
			{
				stienno="sum(a.sdno12+a.fsno12)";
				stienco="sum(a.sdco12+a.fsco12)";
			}
			else 
			{
				int ithang=int.Parse(mm)+1;
				stienno="sum(a.sdno"+ithang.ToString().PadLeft(2,'0')+")";
				stienco="sum(a.sdco"+ithang.ToString().PadLeft(2,'0')+")";
			}
			if(tinhchat.ToString()== "0")sql += ""+stienno+" as tienno,"+stienco+" as tienco,";
			if(tinhchat.ToString()== "1")sql += ""+stienno+" as stien, ";
			if(tinhchat.ToString()== "2")sql += ""+stienco+" as stien, ";
			if(lkdich.ToString().Length != 0 || lkdich.ToString().Length == 0)
			{
				sql += " a.idbc,a.chuong as chuong,a.lk as lk,a.khoanmuc as kmcp,a.khoanmuc2 as kmcp2,a.khoanmuc3 as kmcp3,a.khoanmuc4 as kmcp4,";
				sql +=" a.nghiepvu as dtth,a.mtmuc as mtm,a.madt as madt,a.hoatdong as hoatdong,a.stka as idtk,b.stk as sotk " + " ";//dt.loaidt as loaidt,
			}
			else sql += "a.idbc,a.chuong as chuong,a.lk as lk,a.khoanmuc as kmcp,a.nghiepvu as dtth,a.stka as idtk,a.mtmuc as mtm,a.madt as madt,a.hoatdong as hostdong,b.stk as sotk " + " ";
			sql += "from "+a.user+".a_sd" + yy + " a left join "+a.user+".a_dmtk b on a.stka=b.id " + " ";
			//sql+=" inner join "+a.user+".a_dmdt dt on dt.id=a.madt";			
			sql += " where b.stk like '" + stk + "%'" + 
				(idlk.ToString().Length != 0?" and a.lk in (" + idlk + ")" : " ") +
				(idkmcp.ToString().Length != 0?" and a.khoanmuc in (" + idkmcp + ")" : "") +
				(idkmcp2.ToString().Length != 0?" and a.khoanmuc2 in (" + idkmcp2 + ")" : "") +
				(idkmcp3.ToString().Length != 0?" and a.khoanmuc3 in (" + idkmcp3 + ")" : "") +
				(idkmcp4.ToString().Length != 0?" and a.khoanmuc4 in (" + idkmcp4 + ")" : "") +
				(iddtth.ToString().Length != 0?" and a.nghiepvu in (" + iddtth + ")": " ") + "";
			sql += " group by a.idbc,a.chuong,a.lk,a.khoanmuc,a.khoanmuc2,a.khoanmuc3,a.khoanmuc4,a.nghiepvu,a.mtmuc,a.madt,a.hoatdong,a.stka,b.stk";//dt.loaidt
			sql += " order by a.stka";
			try
			{
				ds=new DataSet();
				ds=a.get_data(sql);
				if(ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch{return null;};		
		}
		private void txtLKnguon_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listkmnguon.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listlknguon.Visible)	listlknguon.Focus();
				else SendKeys.Send("{Tab}");
			}		
			else 
				if (e.KeyCode==Keys.Escape) listlknguon.Hide();
		}

		private void txtLKnguon_TextChanged(object sender, System.EventArgs e)
            //thang sua
        {
            if (this.ActiveControl == txtLKnguon)
            {
                //				Filter_List(listlknguon,txtLKnguon.Text.Trim(),"lk","");
                //				listlknguon.BrowseToDmtk(txtLKnguon,txtLKnguon,chkTulkn,txtLKnguon.Location.X,txtLKnguon.Location.Y+txtLKnguon.Height,500,txtLKnguon.Height,100);

                if (txtLKnguon.Text.IndexOf(",") > 0)
                {
                    if (txtLKnguon.Text.Length > txtLKnguon.Text.Trim().IndexOf(",") + 1)
                    {
                        Filter_List(listlknguon, txtLKnguon.Text.Trim().Substring(txtLKnguon.Text.IndexOf(",") + 1, txtLKnguon.Text.Length - 1 - txtLKnguon.Text.IndexOf(",")), "lk", "");
                        listlknguon.BrowseToDmtk(txtLKnguon, txtLKnguon, chkTulkn, txtLKnguon.Location.X, txtLKnguon.Location.Y + txtLKnguon.Height, 500, txtLKnguon.Height, 100);
                    }
                }
                else
                {
                    Filter_List(listlknguon, txtLKnguon.Text.Trim(), "lk", "");
                    listlknguon.BrowseToDmtk(txtLKnguon, txtLKnguon, chkTulkn, txtLKnguon.Location.X, txtLKnguon.Location.Y + txtLKnguon.Height, 500, txtLKnguon.Height, 100);
                }

                if (txtLKnguon.Text.Equals(","))
                {
                    Filter_List(listlknguon, "", "lk", "");
                    listlknguon.BrowseToDmtk(txtLKnguon, txtLKnguon, chkTulkn, txtLKnguon.Location.X, txtLKnguon.Location.Y + txtLKnguon.Height, 500, txtLKnguon.Height, 100);
                }

            }
        }
        //ket thuc sua thang

		private void txtLKnguon_Validated(object sender, System.EventArgs e)
		{
//			string s_lkm="";
//			if(txtLKnguon.Text.IndexOf(",")!=-1)
//			{
//				DataRow r=a.getrowbyid(dtlk,"lk='"+txtLKnguon.Text.Substring(txtLKnguon.Text.IndexOf(",")+1,txtLKnguon.Text.Length-(txtLKnguon.Text.IndexOf(",")+1))+"'");
//				s_lkm+=(r!=null)?r["lk"].ToString():"";		
//				hidelist();
//			}
//			else
//			{
//				DataRow r=a.getrowbyid(dtlk,"lk='"+txtLKnguon.Text+"'");
//				s_lkm+=(r!=null)?r["lk"].ToString():"";		
//				hidelist();
//			}
//			txtLKnguon.Text=s_lkm;
		}

		private void txtLKdich_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listkmdich.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listlkdich.Visible)	listlkdich.Focus();
				else SendKeys.Send("{Tab}");
			}		
			else if (e.KeyCode==Keys.Escape) listlkdich.Hide();
		}

		private void txtLKdich_TextChanged(object sender, System.EventArgs e)
		{
//			if (this.ActiveControl==txtLKdich)
//			{
//				Filter_List(listlkdich,txtLKdich.Text.Trim(),"lk","");
//				listlkdich.BrowseToDmtk(txtLKdich,txtLKdich,txtNhomkmcpn,txtLKdich.Location.X,txtLKdich.Location.Y+txtLKdich.Height,500,txtLKdich.Height,100);
//			}
		}

		private void txtLKdich_Validated(object sender, System.EventArgs e)
		{
//			DataRow r=a.getrowbyid(dtlk,"lk='"+txtLKdich.Text+"'");
//			txtLKdich.Text=(r!=null)?r["lk"].ToString():"";		
//			hidelist();
		}

		private void txtKmcpnguon_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{			
			try
			{
				if (dtkhoanmuc1!=null && b_khoanmuc1)
				{
					if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listkmnguon.Focus();
					else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
					{
						if (listkmnguon.Visible) 
						{
							listkmnguon.Focus();
							SendKeys.Send("{Down}");
						}
						else SendKeys.Send("{Tab}");
					}
				}
				else SendKeys.Send("{Tab}");
			}
			catch{}
		}

		private void txtKmcpnguon_TextChanged(object sender, System.EventArgs e)
		{
//			try
//			{
//				if (this.ActiveControl==txtKmcpnguon && dtkhoanmuc1!=null && b_khoanmuc1)
//				{
//					Filter_List(listkmnguon,txtKmcpnguon.Text.Trim(),"ma","ten");
//					listkmnguon.BrowseToDmtk(txtKmcpnguon,txtKmcpnguon,chkKmcpn,txtKmcpnguon.Location.X,txtKmcpnguon.Location.Y+txtKmcpnguon.Height,500,txtKmcpnguon.Height,100);
//				}
//			}
//			catch{};
		}

		private void txtKmcpnguon_Validated(object sender, System.EventArgs e)
		{
//			txtKmcpnguon.Text="";
//			try
//			{
//				if (txtKmcpnguon.Text!="" && b_khoanmuc1)
//				{
//					DataRow r=a.getrowbyid(dtkhoanmuc1,"ma='"+txtKmcpnguon.Text+"'");
//					txtKmcpnguon.Text=(r!=null)?r["ma"].ToString():"";														
//				}
//			}
//			catch{}
//			hidelist();			
		}

		private void txtKmcpdich_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			try
			{
				if (dtkhoanmucdich1!=null && b_khoanmucdich1)
				{
					if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listkmdich.Focus();
					else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
					{
						if (listkmdich.Visible)	listkmdich.Focus();
						else SendKeys.Send("{Tab}");
					}		
					else if (e.KeyCode==Keys.Escape) listkmdich.Hide();
				}
				else SendKeys.Send("{Tab}");
			}
			catch{}			
		}

		private void txtKmcpdich_TextChanged(object sender, System.EventArgs e)
		{
//			try
//			{
//				if (this.ActiveControl==txtKmcpdich && dtkhoanmucdich1!=null && b_khoanmucdich1)
//				{
//					Filter_List(listkmdich,txtKmcpdich.Text.Trim(),"ma","ten");
//					listkmdich.BrowseToDmtk(txtKmcpdich,txtKmcpdich,txtDtthnguon,txtKmcpdich.Location.X,txtKmcpdich.Location.Y+txtKmcpdich.Height,500,txtKmcpdich.Height,100);
//				}
//			}
//			catch{};

		}

		private void txtKmcpdich_Validated(object sender, System.EventArgs e)
		{
//			txtKmcpdich.Text="";
//			try
//			{
//				if (txtKmcpdich.Text!="" && b_khoanmucdich1)
//				{
//					DataRow r=a.getrowbyid(dtkhoanmucdich1,"ma='"+txtKmcpdich.Text+"'");
//					txtKmcpdich.Text=(r!=null)?r["ma"].ToString():"";																
//				}
//			}
//			catch{}
//			hidelist();			
		}

		private void txtDtthnguon_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listngvunguon.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listngvunguon.Visible)	listngvunguon.Focus();
				else SendKeys.Send("{Tab}");
			}		
			else if (e.KeyCode==Keys.Escape) listngvunguon.Hide();
		}

		private void txtDtthnguon_TextChanged(object sender, System.EventArgs e)
		{
//			if (this.ActiveControl==txtDtthnguon)
//			{
//				Filter_List(listngvunguon,txtDtthnguon.Text.Trim(),"id","");
//				listngvunguon.BrowseToDmtk(txtDtthnguon,txtDtthnguon,chkTuDtthn,txtDtthnguon.Location.X,txtDtthnguon.Location.Y+txtDtthnguon.Height,500,txtDtthnguon.Height,100);
//			}
		}

		private void txtDtthnguon_Validated(object sender, System.EventArgs e)
		{
//			DataRow r=a.getrowbyid(dtnv,"id='"+txtDtthnguon.Text+"'");
//			txtDtthnguon.Text=(r!=null)?r["id"].ToString():"";		
//			hidelist();
		}

		private void txtDtthdich_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listngvudich.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listngvudich.Visible)	listngvudich.Focus();
				else SendKeys.Send("{Tab}");
			}		
			else if (e.KeyCode==Keys.Escape) listngvudich.Hide();
		}

		private void txtDtthdich_TextChanged(object sender, System.EventArgs e)
		{
//			if (this.ActiveControl==txtDtthdich)
//			{
//				Filter_List(listngvudich,txtDtthdich.Text.Trim(),"id","");
//				listngvudich.BrowseToDmtk(txtDtthdich,txtDtthdich,cboKysl,txtDtthdich.Location.X,txtDtthdich.Location.Y+txtDtthdich.Height,500,txtDtthdich.Height,100);
//			}
		}

		private void txtDtthdich_Validated(object sender, System.EventArgs e)
		{
//			DataRow r=a.getrowbyid(dtnv,"id='"+txtDtthdich.Text+"'");
//			txtDtthdich.Text=(r!=null)?r["id"].ToString():"";		
//			hidelist();
		}
		private void getthang()
		{
			if(int.Parse(a.getrowbyid(dtKysl,"ma='"+cboKysl.SelectedValue.ToString()+"'")["id"].ToString().Trim())<=12)
				s_mmt=cboKysl.SelectedValue.ToString();
			else
				if(int.Parse(a.getrowbyid(dtKysl,"ma='"+cboKysl.SelectedValue.ToString()+"'")["id"].ToString().Trim())==13)
				s_mmt="03";
			else
				if(int.Parse(a.getrowbyid(dtKysl,"ma='"+cboKysl.SelectedValue.ToString()+"'")["id"].ToString().Trim())==14)
				s_mmt="06";
			else
				if(int.Parse(a.getrowbyid(dtKysl,"ma='"+cboKysl.SelectedValue.ToString()+"'")["id"].ToString().Trim())==15)
				s_mmt="09";
			else s_mmt="12";		
		}
		private void butketchuyen_Click(object sender, System.EventArgs e)
		{
			getthang();
			//Kiem tra va canh bao cac thang chua tinh so du.
			string s_Thangnam=a.kt_Tinhsodu(s_mmt.ToString().Trim().Substring(1,1),s_yy);
			if (s_Thangnam!="")
			{
				MessageBox.Show("Các tháng "+s_Thangnam.Substring(0,s_Thangnam.Length-1)+" chưa tính số dư!","Chú ý!");
				//xac minh co tinh so du
				if (MessageBox.Show ("Bạn có muốn kiểm tra số dư không ?",this.Text,MessageBoxButtons.YesNo, MessageBoxIcon.Question)== DialogResult.Yes)
				{
					//tinh so du
					string sql="",_tu="",_den="";
					_den=s_mmt+s_yyyy.Substring(2,2);			
					//lay thang tu						
					sql="select mmyy from (select *  from a_dtsd where substr(trim(mmyy),3,4)='"+s_yy+"' order by mmyy asc) where rownum=1";
					DataSet ds=new DataSet();
					ds=a.get_data(sql);
					if(ds!=null && ds.Tables[0].Rows.Count>0)
						_tu=ds.Tables[0].Rows[0]["mmyy"].ToString();
					else _tu=s_mmt+s_yyyy.Substring(2,2);			
					if (!a.bYyyy(s_yyyy))
					{
						MessageBox.Show("Số liệu năm "+s_yyyy+" chưa tạo !",a.Msg);
						return;
					}
					string s=a.KiemtraFb(_tu,_den);
					if (s!="")
					{
						MessageBox.Show("Số liệu tháng :"+s.Substring(0,s.Length-1)+" Năm "+s_yyyy+" bị khóa !");    		
						return;
					}
					else 
					{
						Cursor=Cursors.WaitCursor;
						a.KiemtraFb(_tu,_den,i_userId);
						Cursor=Cursors.Default;
					}
					//a.updSodu(_tu,a.Mmyy_sau(_den),i_Iduser,false);
					MessageBox.Show("Đã kiểm tra số dư cuối tháng "+_tu.Substring(0,2)+" đến tháng "+_den.Substring(0,2)+" năm 20"+s_yy+" !",a.Msg);					
					//
				}
				return;
			}			
			foreach(DataRow r in dtkc.Rows) 
			{
				string s_idlk="",s_idlkdich="",s_iddtth="",s_iddtthdich="",s_sobtoan="",s_tenbtoan="";
				string s_idkmcp="",s_idkmcp2="",s_idkmcp3="",s_idkmcp4="",s_idkmcpdich="",s_idkmcpdich2="",s_idkmcpdich3="",s_idkmcpdich4="";
				long l_kmcpno=0,l_kmcpco=0,l_kmcpno2=0,l_kmcpco2=0,l_kmcpno3=0,l_kmcpco3=0,l_kmcpno4=0,l_kmcpco4=0;
				string s_noco="",s_tutk="",s_sangtk="";
				int i_chuong=0,i_hoatdong=0,i_nghiepvu=0,i_idbc=0;
				long l_idct=0,l_idctct=0,l_mtmno=0,l_mtmco=0,l_dt=0,l_loaidt=0;
				decimal d_no=0,d_co=0,d_tien=0;
				if(int.Parse(r["ketchuyen"].ToString())==1)
				{				
					s_noco=r["tinhchat"].ToString().Trim();
					s_tutk=r["tentutk"].ToString().Trim();
					s_sangtk=r["tensangtk"].ToString().Trim();
					s_sobtoan=r["sobtoan"].ToString().Trim();
					s_tenbtoan=r["tenbt"].ToString().Trim();
					if(r["lknguon"].ToString().Trim()!="")s_idlk=a.getrowbyid(dtlk,"lk='"+r["lknguon"].ToString().Trim()+"'")["id"].ToString().Trim();
					if(r["lkdich"].ToString().Trim()!="")s_idlkdich=a.getrowbyid(dtlk,"lk='"+r["lkdich"].ToString().Trim()+"'")["id"].ToString().Trim();
					if(r["dtthnguon"].ToString().Trim()!="")s_iddtth=r["dtthnguon"].ToString().Trim();
					if(r["dtthdich"].ToString().Trim()!="")s_iddtthdich=r["dtthdich"].ToString().Trim();
					if(r["akmcpnguon"].ToString().Trim()!="")s_idkmcp=r["akmcpnguon"].ToString().Trim();
					if(r["akmcpnguon2"].ToString().Trim()!="")s_idkmcp2=r["akmcpnguon2"].ToString().Trim();
					if(r["akmcpnguon3"].ToString().Trim()!="")s_idkmcp3=r["akmcpnguon3"].ToString().Trim();
					if(r["akmcpnguon4"].ToString().Trim()!="")s_idkmcp4=r["akmcpnguon4"].ToString().Trim();
					if(r["akmcpdich"].ToString().Trim()!="")s_idkmcpdich=r["akmcpdich"].ToString().Trim();
					if(r["akmcpdich2"].ToString().Trim()!="")s_idkmcpdich2=r["akmcpdich2"].ToString().Trim();
					if(r["akmcpdich3"].ToString().Trim()!="")s_idkmcpdich3=r["akmcpdich3"].ToString().Trim();
					if(r["akmcpdich4"].ToString().Trim()!="")s_idkmcpdich4=r["akmcpdich4"].ToString().Trim();
					DataSet dskc=new DataSet();
					dskc=chungtuketchuyen(s_mmt,s_yy,s_noco,s_tutk,s_idlk,s_idkmcp,s_idkmcp2,s_idkmcp3,s_idkmcp4,s_iddtth,s_sangtk,s_idkmcpdich,s_idkmcpdich2,s_idkmcpdich3,s_idkmcpdich4,s_iddtthdich);					
					string s_tinhchat="",s_tkno="",s_tkco="";
					s_tinhchat=r["tinhchat"].ToString().Trim();
					string s_ngaythang="";
					#region Lay ngaygs
					switch(cboKysl.SelectedValue.ToString())
					{
						case "01":
							s_ngaythang="31/01/"+s_yyyy+"";
							break;
						case "02":
							s_ngaythang="28/02/"+s_yyyy+"";
							break;
						case "03":
							s_ngaythang="31/03/"+s_yyyy+"";
							break;
						case "04":
							s_ngaythang="30/04/"+s_yyyy+"";
							break;
						case "05":
							s_ngaythang="31/05/"+s_yyyy+"";
							break;
						case "06":
							s_ngaythang="30/06/"+s_yyyy+"";
							break;
						case "07":
							s_ngaythang="31/07/"+s_yyyy+"";
							break;
						case "08":
							s_ngaythang="31/08/"+s_yyyy+"";
							break;
						case "09":
							s_ngaythang="30/09/"+s_yyyy+"";
							break;
						case "10":
							s_ngaythang="31/10/"+s_yyyy+"";
							break;
						case "11":
							s_ngaythang="30/10/"+s_yyyy+"";
							break;
						case "12":
							s_ngaythang="31/12/"+s_yyyy+"";
							break;
						case "13":
							s_ngaythang="31/03/"+s_yyyy+"";
							break;
						case "14":
							s_ngaythang="30/06/"+s_yyyy+"";
							break;
						case "15":
							s_ngaythang="30/09/"+s_yyyy+"";
							break;
						case "16":
							s_ngaythang="31/12/"+s_yyyy+"";
							break;
					}
					#endregion dong lay ngaygs
					#region duyet dskc
					if(dskc!=null && dskc.Tables[0].Rows.Count>0)
					foreach(DataRow rs in dskc.Tables[0].Rows)
					{	
						i_idbc=int.Parse(rs["idbc"].ToString().Trim());
						i_chuong=int.Parse(rs["chuong"].ToString().Trim());
						i_hoatdong=int.Parse(rs["hoatdong"].ToString().Trim());
						l_dt=long.Parse(rs["madt"].ToString().Trim());
//						l_loaidt=long.Parse(rs["loaidt"].ToString().Trim());						
						#region switch s_tinhchat
						switch(s_tinhchat)
						{
							case "1"://tinh chat no	
								l_mtmno=long.Parse(rs["mtm"].ToString().Trim());
								s_tkno=r["sangtk"].ToString().Trim();
								if(r["akmcpdich"].ToString().Trim()!="")l_kmcpno=long.Parse(r["akmcpdich"].ToString().Trim());
								if(r["akmcpdich2"].ToString().Trim()!="")l_kmcpno2=long.Parse(r["akmcpdich2"].ToString().Trim());
								if(r["akmcpdich3"].ToString().Trim()!="")l_kmcpno3=long.Parse(r["akmcpdich3"].ToString().Trim());
								if(r["akmcpdich4"].ToString().Trim()!="")l_kmcpno4=long.Parse(r["akmcpdich4"].ToString().Trim());
								s_tkco=r["tutk"].ToString().Trim();										
								if(r["akmcpnguon"].ToString().Trim()!="")l_kmcpco=long.Parse(r["akmcpnguon"].ToString().Trim());
								if(r["akmcpnguon"].ToString().Trim()!="")l_kmcpco2=long.Parse(r["akmcpnguon2"].ToString().Trim());
								if(r["akmcpnguon"].ToString().Trim()!="")l_kmcpco3=long.Parse(r["akmcpnguon3"].ToString().Trim());
								if(r["akmcpnguon"].ToString().Trim()!="")l_kmcpco4=long.Parse(r["akmcpnguon4"].ToString().Trim());								
								d_tien+=Decimal.Parse(rs["stien"].ToString().Trim());								
								break;
							case "2"://tinh chat co
								l_mtmco=long.Parse(rs["mtm"].ToString().Trim());
								s_tkco=r["sangtk"].ToString().Trim();
								s_tkno=r["tutk"].ToString().Trim();
								d_tien+=Decimal.Parse(rs["stien"].ToString().Trim());
								break;
							case "0"://tinh luong tinh
								d_no=Decimal.Parse(rs["tienno"].ToString().Trim());
								d_co=Decimal.Parse(rs["tienco"].ToString().Trim());									
								if(d_no!=0)
								{
									s_tkno=r["sangtk"].ToString().Trim();
									s_tkco=r["tutk"].ToString().Trim();
									d_tien+=Decimal.Parse(rs["tienno"].ToString().Trim());
								}
								else if(d_co!=0)
								{
									s_tkco=r["sangtk"].ToString().Trim();
									s_tkno=r["tutk"].ToString().Trim();
									d_tien+=Decimal.Parse(rs["tienco"].ToString().Trim());
								}	
								break;
						}
						#endregion dong switch s_tinhchat	
						
						
					}
					#endregion duyet dskc
					if (d_tien!=0)
					{
						#region kiem tra: neu da ket chuyen->ko ket chuyen nua, nguoc lai->ket chuyen
//						string sql="";
//						sql="select * from a_ct09 where thanggs='"+s_mmt+"' and soctg='"+r["sobtoan"].ToString()+"'";
//						if(a.get_data(sql)!=null && a.get_data(sql).Tables[0].Rows.Count>0)
//						{
//							MessageBox.Show("Chứng từ đã kết chuyển");
//							return;
//						}

						#endregion end kiem tra
						l_idct=a.getIdct();
						l_idctct=a.getIdctct();		
						#region get idlk
						int i_idlk=0;
						if(s_idlkdich!="")i_idlk = int.Parse(s_idlkdich);
						else if(s_idlk!="")i_idlk = int.Parse(s_idlk);
						#endregion end get idlk						
						if(!a.updCt(s_mmyy,l_idct,0,"",int.Parse(i_chuong.ToString()),6,int.Parse(i_hoatdong.ToString()),37,s_sobtoan,s_ngaythang,s_ngaythang,s_tenbtoan,long.Parse(s_tkno),long.Parse(s_tkco),0,long.Parse(l_dt.ToString()),d_tien,0,s_mmt,int.Parse(i_nghiepvu.ToString()),0,0,0,"",0,i_userId))
						{
							MessageBox.Show("Không cập nhật chứng từ!");
							return;
						}
						else if(!a.updCtct(s_mmyy,l_idctct,l_idct,0,i_idlk,s_tenbtoan,long.Parse(s_tkno),
							long.Parse(s_tkco),l_kmcpno,l_kmcpco,l_kmcpno2,l_kmcpco2,l_kmcpno3,l_kmcpco3,l_kmcpno4,l_kmcpco4,l_mtmno,l_mtmco,d_tien,
							0,0,0,1,0,0,0,s_sobtoan,DateTime.Now.ToString(),i_chuong,0,i_nghiepvu,l_dt,i_hoatdong,i_userId))							
						{
							MessageBox.Show("Không cập nhật chứng từ chi tiết!");
							return;
						}						
						MessageBox.Show("Đã kết chuyển xong!");
						load_gridct();
					}
					else 
						MessageBox.Show("Không có chứng từ kết chuyển!");
				}
			}			
		}
		private void txtKmcpnguon2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			try
			{
				if (dtkhoanmuc2!=null && b_khoanmuc2)
				{
					if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listKmcpnguon2.Focus();
					else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
					{
						if (listKmcpnguon2.Visible) 
						{
							listKmcpnguon2.Focus();
							SendKeys.Send("{Down}");
						}
						else SendKeys.Send("{Tab}");
					}
				}
				else SendKeys.Send("{Tab}");
			}
			catch{}
		}

		private void txtKmcpnguon2_TextChanged(object sender, System.EventArgs e)
		{
//			try
//			{
//				if (this.ActiveControl==txtKmcpnguon2 && dtkhoanmuc2!=null && b_khoanmuc2)
//				{
//					Filter_List(listKmcpnguon2,txtKmcpnguon2.Text.Trim(),"ma","ten");
//					listKmcpnguon2.BrowseToDmtk(txtKmcpnguon2,txtKmcpnguon2,chkkmcpnguon2,txtKmcpnguon2.Location.X,txtKmcpnguon2.Location.Y+txtKmcpnguon2.Height,500,txtKmcpnguon2.Height,100);
//				}
//			}
//			catch{};
		}

		private void txtKmcpnguon2_Validated(object sender, System.EventArgs e)
		{
//			txtKmcpnguon2.Text="";
//			try
//			{
//				if (txtKmcpnguon2.Text!="" && b_khoanmuc2)
//				{
//					DataRow r=a.getrowbyid(dtkhoanmuc2,"ma='"+txtKmcpnguon2.Text+"'");
//					txtKmcpnguon2.Text=(r!=null)?r["ma"].ToString():"";															
//				}
//			}
//			catch{}
//			hidelist();	
		}

		private void txtKmcpdich2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			try
			{
				if (dtkhoanmucdich2!=null && b_khoanmucdich2)
				{
					if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listkmcpdich2.Focus();
					else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
					{
						if (listkmcpdich2.Visible)	listkmcpdich2.Focus();
						else SendKeys.Send("{Tab}");
					}		
					else if (e.KeyCode==Keys.Escape) listkmcpdich2.Hide();
				}
				else SendKeys.Send("{Tab}");
			}
			catch{}	
		}

		private void txtKmcpdich2_TextChanged(object sender, System.EventArgs e)
		{
//			try
//			{
//				if (this.ActiveControl==txtKmcpdich2 && dtkhoanmucdich2!=null && b_khoanmucdich2)
//				{
//					Filter_List(listkmcpdich2,txtKmcpdich2.Text.Trim(),"ma","ten");
//					listkmcpdich2.BrowseToDmtk(txtKmcpdich2,txtKmcpdich2,txtKmcpnguon3,txtKmcpdich2.Location.X,txtKmcpdich2.Location.Y+txtKmcpdich2.Height,500,txtKmcpdich2.Height,100);
//				}
//			}
//			catch{};			
		}

		private void txtKmcpnguon3_TextChanged(object sender, System.EventArgs e)
		{
//			try
//			{
//				if (this.ActiveControl==txtKmcpnguon3 && dtkhoanmuc3!=null && b_khoanmuc3)
//				{
//					
//					Filter_List(listKmcpnguon3,txtKmcpnguon3.Text.Trim(),"ma","ten");
//					listKmcpnguon3.BrowseToDmtk(txtKmcpnguon3,txtKmcpnguon3,chkKmcpnguon3,txtKmcpnguon3.Location.X,txtKmcpnguon3.Location.Y+txtKmcpnguon3.Height,500,txtKmcpnguon3.Height,100);
//				}
//			}
//			catch{};
		}

		private void txtKmcpnguon3_Validated(object sender, System.EventArgs e)
		{
//			txtKmcpnguon3.Text="";
//			try
//			{
//				if (txtKmcpnguon3.Text!="" && b_khoanmuc3)
//				{
//					DataRow r=a.getrowbyid(dtkhoanmuc3,"ma='"+txtKmcpnguon3.Text+"'");
//					txtKmcpnguon3.Text=(r!=null)?r["ma"].ToString():"";															
//				}
//			}
//			catch{}
//			hidelist();	
		}

		private void txtKmcpdich3_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			try
			{
				if (dtkhoanmucdich3!=null && b_khoanmucdich3)
				{
					if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listKmcpdich3.Focus();
					else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
					{
						if (listKmcpdich3.Visible)	listKmcpdich3.Focus();
						else SendKeys.Send("{Tab}");
					}		
					else if (e.KeyCode==Keys.Escape) listKmcpdich3.Hide();
				}
				else SendKeys.Send("{Tab}");
			}
			catch{}	
		}

		private void txtKmcpdich3_TextChanged(object sender, System.EventArgs e)
		{
//			try
//			{
//				if (this.ActiveControl==txtKmcpdich3 && dtkhoanmucdich3!=null && b_khoanmucdich3)
//				{
//					Filter_List(listKmcpdich3,txtKmcpdich3.Text.Trim(),"ma","ten");
//					listKmcpdich3.BrowseToDmtk(txtKmcpdich3,txtKmcpdich3,txtKmcpnguon4,txtKmcpdich3.Location.X,txtKmcpdich3.Location.Y+txtKmcpdich3.Height,500,txtKmcpdich3.Height,100);
//				}
//			}
//			catch{};
		}

		private void txtKmcpnguon4_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			try
			{
				if (dtkhoanmuc4!=null && b_khoanmuc4)
				{
					if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listKmcpnguon4.Focus();
					else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
					{
						if (listKmcpnguon4.Visible) 
						{
							listKmcpnguon4.Focus();
							SendKeys.Send("{Down}");
						}
						else SendKeys.Send("{Tab}");
					}
				}
				else SendKeys.Send("{Tab}");
			}
			catch{}
		}

		private void txtKmcpdich3_Validated(object sender, System.EventArgs e)
		{
//			txtKmcpdich3.Text="";
//			try
//			{
//				if (txtKmcpdich3.Text!="" && b_khoanmucdich3)
//				{
//					DataRow r=a.getrowbyid(dtkhoanmucdich3,"ma='"+txtKmcpdich3.Text+"'");
//					txtKmcpdich3.Text=(r!=null)?r["ma"].ToString():"";																
//				}
//			}
//			catch{}
//			hidelist();
		}

		private void txtKmcpnguon4_TextChanged(object sender, System.EventArgs e)
		{
//			try
//			{
//				if (this.ActiveControl==txtKmcpnguon4 && dtkhoanmuc4!=null && b_khoanmuc4)
//				{
//					
//					Filter_List(listKmcpnguon4,txtKmcpnguon4.Text.Trim(),"ma","ten");
//					listKmcpnguon4.BrowseToDmtk(txtKmcpnguon4,txtKmcpnguon4,chkKmcpnguon4,txtKmcpnguon4.Location.X,txtKmcpnguon4.Location.Y+txtKmcpnguon4.Height,500,txtKmcpnguon4.Height,100);
//				}
//			}
//			catch{};
		}

		private void txtKmcpnguon4_Validated(object sender, System.EventArgs e)
		{
//			txtKmcpnguon4.Text="";
//			try
//			{
//				if (txtKmcpnguon4.Text!="" && b_khoanmuc4)
//				{
//					DataRow r=a.getrowbyid(dtkhoanmuc4,"ma='"+txtKmcpnguon4.Text+"'");
//					txtKmcpnguon4.Text=(r!=null)?r["ma"].ToString():"";														
//				}
//			}
//			catch{}
//			hidelist();	
		}

		private void txtKmcpdich4_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			try
			{
				if (dtkhoanmucdich4!=null && b_khoanmucdich4)
				{
					if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listKmcpdich4.Focus();
					else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
					{
						if (listKmcpdich4.Visible)	listKmcpdich4.Focus();
						else SendKeys.Send("{Tab}");
					}		
					else if (e.KeyCode==Keys.Escape) listKmcpdich4.Hide();
				}
				else SendKeys.Send("{Tab}");
			}
			catch{}				
		}

		private void txtKmcpdich4_TextChanged(object sender, System.EventArgs e)
		{
//			try
//			{
//				if (this.ActiveControl==txtKmcpdich4 && dtkhoanmucdich4!=null && b_khoanmucdich4)
//				{
//					Filter_List(listKmcpdich4,txtKmcpdich4.Text.Trim(),"ma","ten");
//					listKmcpdich4.BrowseToDmtk(txtKmcpdich4,txtKmcpdich4,txtDtthnguon,txtKmcpdich4.Location.X,txtKmcpdich4.Location.Y+txtKmcpdich4.Height,500,txtKmcpdich4.Height,100);
//				}
//			}
//			catch{};
		}

		private void txtKmcpdich2_Validated(object sender, System.EventArgs e)
		{
//			txtKmcpdich2.Text="";
//			try
//			{
//				if (txtKmcpdich2.Text!="" && b_khoanmucdich2)
//				{
//					DataRow r=a.getrowbyid(dtkhoanmucdich2,"ma='"+txtKmcpdich2.Text+"'");
//					txtKmcpdich2.Text=(r!=null)?r["ma"].ToString():"";																
//				}
//			}
//			catch{}
//			hidelist();	
		}

		private void txtKmcpdich4_Validated(object sender, System.EventArgs e)
		{
//			txtKmcpdich4.Text="";
//			try
//			{
//				if (txtKmcpdich4.Text!="" && b_khoanmucdich4)
//				{
//					DataRow r=a.getrowbyid(dtkhoanmucdich4,"ma='"+txtKmcpdich4.Text+"'");
//					txtKmcpdich4.Text=(r!=null)?r["ma"].ToString():"";																	
//				}
//			}
//			catch{}
//			hidelist();
		}

		private void txtKmcpnguon_Enter(object sender, System.EventArgs e)
		{
			string s_IDloaikm="";				
			if (txtTutk.Text!="")
			{
				s_IDloaikm=a.getrowbyid(dttk,"stk='"+txtTutk.Text.Trim()+"'")["loaikm"].ToString().Trim();
				f_LoadKhoanmuc(ref listkmnguon,ref dtkhoanmuc1,s_IDloaikm);
				b_khoanmuc1=true;
			}
			else
			{
				b_khoanmuc1=false;
				txtKmcpnguon.Text="";
				SendKeys.Send("{Tab}");				
			}				
		}

		private void txtKmcpdich_Enter(object sender, System.EventArgs e)
		{
			string s_IDloaikm="";				
			if (txtSangtk.Text!="")
			{
				s_IDloaikm=a.getrowbyid(dttk,"stk='"+txtSangtk.Text.Trim()+"'")["loaikm"].ToString().Trim();
				f_LoadKhoanmuc(ref listkmdich,ref dtkhoanmucdich1,s_IDloaikm);
				b_khoanmucdich1=true;
			}
			else
			{
				b_khoanmucdich1=false;
				txtKmcpdich.Text="";
				SendKeys.Send("{Tab}");				
			}				
		}

		private void txtKmcpnguon2_Enter(object sender, System.EventArgs e)
		{
			string s_IDloaikm="";				
			if (txtTutk.Text!="")
			{
				s_IDloaikm=a.getrowbyid(dttk,"stk='"+txtTutk.Text.Trim()+"'")["loaikm2"].ToString().Trim();
				f_LoadKhoanmuc(ref listKmcpnguon2,ref dtkhoanmuc2,s_IDloaikm);
				b_khoanmuc2=true;
			}
			else
			{
				b_khoanmuc2=false;
				txtKmcpnguon2.Text="";
				SendKeys.Send("{Tab}");				
			}				
		}

		private void txtKmcpnguon3_Enter(object sender, System.EventArgs e)
		{
			string s_IDloaikm="";				
			if (txtTutk.Text!="")
			{
				s_IDloaikm=a.getrowbyid(dttk,"stk='"+txtTutk.Text.Trim()+"'")["loaikm3"].ToString().Trim();
				f_LoadKhoanmuc(ref listKmcpnguon3,ref dtkhoanmuc3,s_IDloaikm);
				b_khoanmuc3=true;
			}
			else
			{
				b_khoanmuc3=false;
				txtKmcpnguon3.Text="";
				SendKeys.Send("{Tab}");				
			}				
		}

		private void txtKmcpnguon4_Enter(object sender, System.EventArgs e)
		{
			string s_IDloaikm="";				
			if (txtTutk.Text!="")
			{
				s_IDloaikm=a.getrowbyid(dttk,"stk='"+txtTutk.Text.Trim()+"'")["loaikm4"].ToString().Trim();
				f_LoadKhoanmuc(ref listKmcpnguon4,ref dtkhoanmuc4,s_IDloaikm);
				b_khoanmuc4=true;
			}
			else
			{
				b_khoanmuc4=false;
				txtKmcpnguon4.Text="";
				SendKeys.Send("{Tab}");				
			}				
		}

		private void txtKmcpdich2_Enter(object sender, System.EventArgs e)
		{
			string s_IDloaikm="";				
			if (txtSangtk.Text!="")
			{
				s_IDloaikm=a.getrowbyid(dttk,"stk='"+txtSangtk.Text.Trim()+"'")["loaikm2"].ToString().Trim();
				f_LoadKhoanmuc(ref listkmcpdich2,ref dtkhoanmucdich2,s_IDloaikm);
				b_khoanmucdich2=true;
			}
			else
			{
				b_khoanmucdich2=false;
				txtKmcpdich2.Text="";
				SendKeys.Send("{Tab}");				
			}			
		}

		private void txtKmcpdich3_Enter(object sender, System.EventArgs e)
		{
			string s_IDloaikm="";				
			if (txtSangtk.Text!="")
			{
				s_IDloaikm=a.getrowbyid(dttk,"stk='"+txtSangtk.Text.Trim()+"'")["loaikm3"].ToString().Trim();
				f_LoadKhoanmuc(ref listKmcpdich3,ref dtkhoanmucdich3,s_IDloaikm);
				b_khoanmucdich3=true;
			}
			else
			{
				b_khoanmucdich3=false;
				txtKmcpdich3.Text="";
				SendKeys.Send("{Tab}");				
			}			
		}

		private void txtKmcpdich4_Enter(object sender, System.EventArgs e)
		{
			string s_IDloaikm="";				
			if (txtSangtk.Text!="")
			{
				s_IDloaikm=a.getrowbyid(dttk,"stk='"+txtSangtk.Text.Trim()+"'")["loaikm4"].ToString().Trim();
				f_LoadKhoanmuc(ref listKmcpdich4,ref dtkhoanmucdich4,s_IDloaikm);
				b_khoanmucdich4=true;
			}
			else
			{
				b_khoanmucdich4=false;
				txtKmcpdich4.Text="";
				SendKeys.Send("{Tab}");				
			}			
		}

		private void txtKmpnguon3_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			try
			{
				if (dtkhoanmuc3!=null && b_khoanmuc3)
				{
					if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listKmcpnguon3.Focus();
					else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
					{
						if (listKmcpnguon3.Visible) 
						{
							listKmcpnguon3.Focus();
							SendKeys.Send("{Down}");
						}
						else SendKeys.Send("{Tab}");
					}
				}
				else SendKeys.Send("{Tab}");
			}
			catch{}
		}

		private void butXoa_Click(object sender, System.EventArgs e)
		{
			long l_idct=long.Parse(dataGrid2[dataGrid2.CurrentRowIndex,0].ToString() );
			a.get_data("delete from a_ct"+s_yy+" where id="+l_idct);
			a.get_data("delete from a_ctct"+s_yy+" where idct="+l_idct);
			MessageBox.Show("Đã xoá chứng từ kết chuyển!");	
			load_gridct();
		}

		private void dataGrid2_CurrentCellChanged(object sender, System.EventArgs e)
		{
			butXoa.Enabled=true;
		}
		private bool IsLoaded(string frm)
		{
			Form[] afrm=this.MdiChildren;
			foreach(Form f in afrm)
			{
				if(f.Name.Equals(frm)){f.Activate();return true;}
			}
			return false;
		}
		private void butlaymau_Click(object sender, System.EventArgs e)
		{
			if(IsLoaded("frmMauketchuyen"))return ;
			frmMauketchuyen f = new frmMauketchuyen(a,s_yy,int.Parse(cboKysl.SelectedValue.ToString())<=12?cboKysl.SelectedValue.ToString().Substring(1,1):cboKysl.SelectedValue.ToString(),i_userId,s_mmyy,s_yyyy);
			f.ShowDialog();

			load_grid_ketchuyen(int.Parse(cboKysl.SelectedValue.ToString())<=12?cboKysl.SelectedValue.ToString().Substring(1,1):cboKysl.SelectedValue.ToString());	
		}

		private void butcoppy_Click(object sender, System.EventArgs e)
		{
			frmSaochep f = new frmSaochep(a,int.Parse(cboKysl.SelectedValue.ToString())<=12?int.Parse(cboKysl.SelectedValue.ToString().Substring(1,1)):int.Parse(cboKysl.SelectedValue.ToString()),s_yyyy,s_yy,i_userId);
			f.Show();
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			load_gridct();
		}

		private void chkTulkn_CheckedChanged(object sender, System.EventArgs e)
		{
			if(chkTulkn.Checked) txtLKdich.Enabled=false;
			else 
				txtLKdich.Enabled=true;
		}

		private void chkKmcpn_CheckedChanged(object sender, System.EventArgs e)
		{
			if(chkKmcpn.Checked)txtKmcpdich.Enabled=false;
			else txtKmcpdich.Enabled=true;
		}

		private void chkkmcpnguon2_CheckedChanged(object sender, System.EventArgs e)
		{
			if(chkkmcpnguon2.Checked)txtKmcpdich2.Enabled=false;
			else txtKmcpdich2.Enabled=true;
		}

		private void chkKmcpnguon3_CheckedChanged(object sender, System.EventArgs e)
		{
			if(chkKmcpnguon3.Checked)txtKmcpdich3.Enabled=false;
			else txtKmcpdich3.Enabled=true;
		}

		private void chkKmcpnguon4_CheckedChanged(object sender, System.EventArgs e)
		{
			if(chkKmcpnguon4.Checked)txtKmcpdich4.Enabled=false;
			else txtKmcpdich4.Enabled=true;
		}

		private void chkTuDtthn_CheckedChanged(object sender, System.EventArgs e)
		{
			if(chkTuDtthn.Checked)txtDtthdich.Enabled=false;
			else txtDtthdich.Enabled=true;
		}
		
	}
}
